72 lines
2.2 KiB
C#
72 lines
2.2 KiB
C#
using System;
|
|
using NodeCanvas.Framework;
|
|
using ParadoxNotion.Design;
|
|
using Reset.Movement;
|
|
using Reset.Units;
|
|
using UnityEngine;
|
|
|
|
namespace NodeCanvas.Tasks.Actions {
|
|
|
|
[Category("Reset/Movement")]
|
|
[Description("Launch the agent towards a specific point with respect to distance.")]
|
|
public class StartLaunchJump : ActionTask<CharacterController>{
|
|
public BBParameter<Vector3> airDirection;
|
|
public BBParameter<float> jumpPower;
|
|
|
|
public BBParameter<Vector3> targetLocation;
|
|
public BBParameter<Vector3> offset;
|
|
|
|
public BBParameter<Vector3> relativeRotation;
|
|
|
|
public BBParameter<PlayerFacingDirection> launchRelativeTo;
|
|
|
|
|
|
public BBParameter<bool> useRelativeForce;
|
|
[ShowIf("useRelativeForce", 1)] public BBParameter<float> minimumForce;
|
|
[ShowIf("useRelativeForce", 1)] public BBParameter<float> maximumForce;
|
|
[ShowIf("useRelativeForce", 1)] public BBParameter<float> forceRelativeToDistance;
|
|
public BBParameter<float> force;
|
|
|
|
//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(){
|
|
Vector3 launchDir = agent.transform.position.DirectionTo(targetLocation.value).normalized;
|
|
launchDir = Quaternion.Euler(relativeRotation.value) * launchDir;
|
|
|
|
Debug.Log(launchDir);
|
|
|
|
float distanceToTarget = Vector3.Distance(agent.transform.position, targetLocation.value);
|
|
|
|
float outputForce = (useRelativeForce.value ? distanceToTarget * forceRelativeToDistance.value : force.value);
|
|
|
|
outputForce = Mathf.Clamp(outputForce, minimumForce.value, maximumForce.value);
|
|
jumpPower.value = outputForce;
|
|
|
|
airDirection.value = (launchDir * outputForce);
|
|
|
|
EndAction(true);
|
|
}
|
|
|
|
//Called once per frame while the action is active.
|
|
protected override void OnUpdate() {
|
|
|
|
}
|
|
|
|
//Called when the task is disabled.
|
|
protected override void OnStop() {
|
|
|
|
}
|
|
|
|
//Called when the task is paused.
|
|
protected override void OnPause() {
|
|
|
|
}
|
|
}
|
|
} |