fixed: changed how rotation is handled in transition from grounded to air to account for becoming grounded without jumping
This commit is contained in:
@@ -51,7 +51,7 @@ namespace NodeCanvas.Tasks.Actions {
|
||||
// Save current velocity and get current input direction
|
||||
Vector3 currentVelocityVector3 = new Vector3(agent.velocity.x, 0f, agent.velocity.z);
|
||||
Vector2 currentInput = agent.GetComponent<PlayerControls>().rawMoveInput;
|
||||
Vector3 currentInputVector3 = new(currentInput.x, 0f, currentInput.y);
|
||||
Vector3 currentInputVector3 = Camera.main.transform.rotation.Flatten(0, null, 0) * new Vector3(currentInput.x, 0f, currentInput.y);
|
||||
|
||||
// Ignore rotation for the current velocity
|
||||
Vector3 currentVelocityWorld = agent.transform.InverseTransformDirection(currentVelocityVector3.normalized);
|
||||
@@ -93,10 +93,6 @@ namespace NodeCanvas.Tasks.Actions {
|
||||
airMoveDirection.value += outputDirection * outputVelocity;
|
||||
}
|
||||
|
||||
// Transform and apply rotatio
|
||||
|
||||
agent.transform.rotation = Quaternion.LookRotation(airMoveDirection.value);
|
||||
|
||||
EndAction(true);
|
||||
}
|
||||
|
||||
|
||||
@@ -22,6 +22,8 @@ namespace NodeCanvas.Tasks.Actions {
|
||||
//EndAction can be called from anywhere.
|
||||
protected override void OnExecute() {
|
||||
airControlPower = 1f;
|
||||
protected override void OnExecute(){
|
||||
|
||||
}
|
||||
|
||||
//Called once per frame while the action is active.
|
||||
@@ -34,8 +36,9 @@ namespace NodeCanvas.Tasks.Actions {
|
||||
|
||||
// Add air control
|
||||
Vector3 inputVector3 = new(agent.GetComponent<PlayerControls>().rawMoveInput.x, 0f, agent.GetComponent<PlayerControls>().rawMoveInput.y);
|
||||
float originalMagnitude = airMoveDirection.value.magnitude;
|
||||
airMoveDirection.value += Camera.main.transform.rotation * inputVector3 * airControlPower;
|
||||
float originalMagnitude = airMoveDirection.value.magnitude;
|
||||
airMoveDirection.value += Camera.main.transform.rotation.Flatten(0, null, 0) *
|
||||
inputVector3 * airControlPower;
|
||||
|
||||
airMoveDirection.value = Vector3.ClampMagnitude(airMoveDirection.value, originalMagnitude);
|
||||
}
|
||||
|
||||
@@ -96,9 +96,6 @@ namespace NodeCanvas.Tasks.Actions {
|
||||
targetRotation = Quaternion.Euler(Camera.main.transform.rotation.eulerAngles.Flatten(0, null, 0));
|
||||
break;
|
||||
}
|
||||
|
||||
// Set final rotation
|
||||
agent.transform.rotation = Quaternion.Lerp(agent.transform.rotation, targetRotation, 10f * Time.deltaTime);
|
||||
|
||||
// Construct move direction
|
||||
Vector3 finalMoveDir = Vector3.zero;
|
||||
@@ -125,6 +122,9 @@ namespace NodeCanvas.Tasks.Actions {
|
||||
agent.Move((finalMoveDir + gravityMoveDirection) * Time.deltaTime);
|
||||
}
|
||||
|
||||
// Set final rotation
|
||||
agent.transform.rotation = Quaternion.Lerp(agent.transform.rotation, targetRotation, 10f * Time.deltaTime);
|
||||
|
||||
// ???? Moved this above but don't remember if this needs to be here still
|
||||
if (agent.isGrounded) {
|
||||
jumpPower.value = 0f;
|
||||
|
||||
56
Assets/Scripts/Core/Graph Tasks/SetAirMovement.cs
Normal file
56
Assets/Scripts/Core/Graph Tasks/SetAirMovement.cs
Normal file
@@ -0,0 +1,56 @@
|
||||
using NodeCanvas.Framework;
|
||||
using ParadoxNotion.Design;
|
||||
using UnityEngine;
|
||||
|
||||
|
||||
namespace NodeCanvas.Tasks.Actions {
|
||||
|
||||
[Category("Reset")]
|
||||
[Description("Hard set the air direction to a certain direction")]
|
||||
public class SetAirMovement : ActionTask<Transform>{
|
||||
public BBParameter<Vector3> airMoveDirection;
|
||||
|
||||
public BBParameter<Vector3> inputVector3;
|
||||
public Space fromSpace;
|
||||
public Space toSpace;
|
||||
|
||||
//Use for initialization. This is called only once in the lifetime of the task.
|
||||
//Return null if init was successfull. Return an error string otherwise
|
||||
protected override string OnInit() {
|
||||
return null;
|
||||
}
|
||||
|
||||
//This is called once each time the task is enabled.
|
||||
//Call EndAction() to mark the action as finished, either in success or failure.
|
||||
//EndAction can be called from anywhere.
|
||||
protected override void OnExecute(){
|
||||
|
||||
}
|
||||
|
||||
//Called once per frame while the action is active.
|
||||
protected override void OnUpdate() {
|
||||
if (fromSpace == toSpace) {
|
||||
airMoveDirection.value = inputVector3.value;
|
||||
}
|
||||
|
||||
// NOTE: I swear to God these absolutely do not work and nobody could convince me otherwise
|
||||
if (fromSpace == Space.World){
|
||||
airMoveDirection.value = Camera.main.transform.rotation.Flatten(0, null, 0) * inputVector3.value;
|
||||
} else {
|
||||
airMoveDirection.value = Camera.main.transform.rotation.Flatten(0, null, 0) * agent.InverseTransformVector(inputVector3.value);
|
||||
}
|
||||
|
||||
EndAction(true);
|
||||
}
|
||||
|
||||
//Called when the task is disabled.
|
||||
protected override void OnStop() {
|
||||
|
||||
}
|
||||
|
||||
//Called when the task is paused.
|
||||
protected override void OnPause() {
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
2
Assets/Scripts/Core/Graph Tasks/SetAirMovement.cs.meta
Normal file
2
Assets/Scripts/Core/Graph Tasks/SetAirMovement.cs.meta
Normal file
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: f1db555b92ed94543beab7a2106bc2a3
|
||||
Reference in New Issue
Block a user