using NodeCanvas.Framework; using ParadoxNotion.Design; using ParadoxNotion.Services; using UnityEngine; namespace Reset.Movement { [Category("Reset/Movement")] [Description("Process Y-axis movement for the agent")] public class ProcessGravity : ActionTask{ public BBParameter moveDirection; public BBParameter jumpPower; public BBParameter jumpPowerDecay; [Space(5)] public BBParameter gravityAcceleration = 1f; public BBParameter gravityMax = 8f; public BBParameter gravityPower; //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() { MonoManager.current.onLateUpdate += LateUpdate; 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() { // Accelerate gravity gravityPower.value += gravityAcceleration.value * Time.deltaTime; gravityPower.value = Mathf.Min(gravityPower.value, gravityMax.value); Vector3 gravityMoveDirection; gravityMoveDirection = new(0f, jumpPower.value + (Physics.gravity.y * gravityPower.value), 0f); // Reset gravity power when grounded agent.Move((gravityMoveDirection) * Time.deltaTime); if (agent.isGrounded) { gravityPower.value = 0f; jumpPower.value = 0f; } EndAction(true); } public void LateUpdate(){ // Decay jump power jumpPower.value = Mathf.Lerp(jumpPower.value, 0f, jumpPowerDecay.value * Time.deltaTime); } //Called when the task is disabled. protected override void OnStop() { } //Called when the task is paused. protected override void OnPause() { } } }