first commit
This commit is contained in:
54
Assets/Scripts/Core/Graph Tasks/CalculateAirMovement.cs
Normal file
54
Assets/Scripts/Core/Graph Tasks/CalculateAirMovement.cs
Normal file
@@ -0,0 +1,54 @@
|
||||
using NodeCanvas.Framework;
|
||||
using ParadoxNotion.Design;
|
||||
using UnityEngine;
|
||||
|
||||
namespace NodeCanvas.Tasks.Actions {
|
||||
|
||||
[Category("Core/Movement")]
|
||||
public class CalculateAirMovement : ActionTask<Transform>{
|
||||
public BBParameter<Vector3> airMoveDirection;
|
||||
public BBParameter<Vector3> groundMoveDirection;
|
||||
|
||||
private float airControlPower = 1f;
|
||||
|
||||
//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() {
|
||||
airControlPower = 1f;
|
||||
}
|
||||
|
||||
//Called once per frame while the action is active.
|
||||
protected override void OnUpdate() {
|
||||
// Decay Current Air Movement
|
||||
airMoveDirection.value = Vector3.Lerp(airMoveDirection.value, Vector3.zero, .7f * Time.deltaTime);
|
||||
|
||||
// Decay Air Control power
|
||||
airControlPower = Mathf.Lerp(airControlPower, 0f, 3f * Time.deltaTime);
|
||||
|
||||
// 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;
|
||||
|
||||
airMoveDirection.value = Vector3.ClampMagnitude(airMoveDirection.value, originalMagnitude);
|
||||
}
|
||||
|
||||
//Called when the task is disabled.
|
||||
protected override void OnStop() {
|
||||
groundMoveDirection.value = agent.GetComponent<CharacterController>().velocity;
|
||||
EndAction(true);
|
||||
}
|
||||
|
||||
//Called when the task is paused.
|
||||
protected override void OnPause() {
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user