change: separated all functions of movement into separate tasks
This commit is contained in:
60
Assets/Scripts/Core/Graph Tasks/UpdateMovementSpeed.cs
Normal file
60
Assets/Scripts/Core/Graph Tasks/UpdateMovementSpeed.cs
Normal file
@@ -0,0 +1,60 @@
|
||||
using System;
|
||||
using NodeCanvas.Framework;
|
||||
using ParadoxNotion.Design;
|
||||
using UnityEngine;
|
||||
|
||||
|
||||
namespace Reset.Movement {
|
||||
|
||||
[Category("Reset/Movement")]
|
||||
[Description("Updates the movespeed for this agent")]
|
||||
public class UpdateMovementSpeed : ActionTask{
|
||||
public BBParameter<float> target;
|
||||
public BBParameter<float> speed;
|
||||
public BBParameter<float> smoothing = 10f;
|
||||
|
||||
private float currentSpeed;
|
||||
|
||||
//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() {
|
||||
if (!speed.useBlackboard) {
|
||||
Debug.LogError("This <b>Update Movement Speed</b> does not have it's current value attached to a Blackboard variable. Nothing will happen.", agent.gameObject);
|
||||
}
|
||||
|
||||
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(){
|
||||
// currentSpeed = speed.value;
|
||||
|
||||
}
|
||||
|
||||
//Called once per frame while the action is active.
|
||||
protected override void OnUpdate(){
|
||||
currentSpeed = Mathf.Lerp(currentSpeed, target.value, smoothing.value * Time.deltaTime);
|
||||
|
||||
speed.value = currentSpeed;
|
||||
|
||||
if (Mathf.Abs(currentSpeed - speed.value) < .01f) {
|
||||
|
||||
}
|
||||
|
||||
Debug.Log("Speed Done");
|
||||
EndAction(true);
|
||||
}
|
||||
|
||||
//Called when the task is disabled.
|
||||
protected override void OnStop() {
|
||||
|
||||
}
|
||||
|
||||
//Called when the task is paused.
|
||||
protected override void OnPause() {
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user