44 lines
1.2 KiB
C#
44 lines
1.2 KiB
C#
using UnityEngine;
|
|
|
|
namespace BehaviorDesigner.Runtime.Tasks.Movement
|
|
{
|
|
[TaskDescription("Flee from the target specified using the Unity NavMesh.")]
|
|
[TaskIcon("Assets/Behavior Designer Movement/Editor/Icons/{SkinColor}FleeIcon.png")]
|
|
[HelpURLAttribute("http://www.opsive.com/assets/BehaviorDesigner/Movement/documentation.php?id=4")]
|
|
[TaskCategory("Movement")]
|
|
public class Flee : NavMeshMovement
|
|
{
|
|
[Tooltip("The agent has fleed when the magnitude is greater than this value")]
|
|
public SharedFloat fleedDistance = 20f;
|
|
|
|
[Tooltip("The distance to look ahead when fleeing")]
|
|
public SharedFloat lookAheadDistance = 5f;
|
|
|
|
[Tooltip("The GameObject that the agent is fleeing from")]
|
|
public SharedGameObject target;
|
|
|
|
public override TaskStatus OnUpdate()
|
|
{
|
|
if (Vector3.Magnitude(transform.position - target.Value.transform.position) > fleedDistance.Value)
|
|
{
|
|
return TaskStatus.Success;
|
|
}
|
|
SetDestination(Target());
|
|
return TaskStatus.Running;
|
|
}
|
|
|
|
private Vector3 Target()
|
|
{
|
|
return transform.position + (transform.position - target.Value.transform.position).normalized * lookAheadDistance.Value;
|
|
}
|
|
|
|
public override void OnReset()
|
|
{
|
|
base.OnReset();
|
|
fleedDistance = 20f;
|
|
lookAheadDistance = 5f;
|
|
target = null;
|
|
}
|
|
}
|
|
}
|