using NodeCanvas.Framework; using ParadoxNotion.Design; using UnityEngine; namespace NodeCanvas.Tasks.Actions { [Category("Core/Movement")] public class CalculateAirMovement : ActionTask{ public BBParameter airMoveDirection; public BBParameter 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().rawMoveInput.x, 0f, agent.GetComponent().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().velocity; EndAction(true); } //Called when the task is paused. protected override void OnPause() { } } }