first commit
This commit is contained in:
67
Assets/Scripts/Core/Graph Tasks/ProcessGravity.cs
Normal file
67
Assets/Scripts/Core/Graph Tasks/ProcessGravity.cs
Normal file
@@ -0,0 +1,67 @@
|
||||
using NodeCanvas.Framework;
|
||||
using ParadoxNotion.Design;
|
||||
using ParadoxNotion.Services;
|
||||
using UnityEngine;
|
||||
|
||||
namespace NodeCanvas.Tasks.Actions {
|
||||
|
||||
[Category("Core/Movement")]
|
||||
public class ProcessGravity : ActionTask<CharacterController>{
|
||||
public BBParameter<float> gravityScale = 1f;
|
||||
public BBParameter<float> gravityAcceleration = 1f;
|
||||
public BBParameter<float> gravityMax = 8f;
|
||||
|
||||
private Vector3 currentVelocity;
|
||||
private bool freezeVelocity;
|
||||
|
||||
private float 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() {
|
||||
if (!freezeVelocity && agent.velocity != Vector3.zero){
|
||||
currentVelocity = new Vector3(agent.velocity.x, 0f, agent.velocity.y);
|
||||
}
|
||||
}
|
||||
|
||||
void LateUpdate(){
|
||||
if (agent.isGrounded) {
|
||||
gravityPower = 0f;
|
||||
currentVelocity = Vector3.zero;
|
||||
freezeVelocity = true;
|
||||
agent.Move(Physics.gravity * .1f * Time.deltaTime);
|
||||
|
||||
} else {
|
||||
if (currentVelocity == Vector3.zero && agent.velocity.y < 0f) {
|
||||
freezeVelocity = false;
|
||||
}
|
||||
|
||||
Debug.Log(currentVelocity);
|
||||
|
||||
agent.Move((Physics.gravity * gravityPower * Time.deltaTime));
|
||||
}
|
||||
}
|
||||
|
||||
//Called when the task is disabled.
|
||||
protected override void OnStop() {
|
||||
EndAction(true);
|
||||
}
|
||||
|
||||
//Called when the task is paused.
|
||||
protected override void OnPause() {
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user