Files
project-reset/Assets/Scripts/Core/Graph Tasks/CalculateAirMovement.cs

57 lines
1.9 KiB
C#

using NodeCanvas.Framework;
using ParadoxNotion.Design;
using UnityEngine;
namespace NodeCanvas.Tasks.Actions {
[Category("Reset/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;
protected override void OnExecute(){
}
//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.Flatten(0, null, 0) *
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() {
}
}
}