45 lines
1.1 KiB
C#
45 lines
1.1 KiB
C#
using UnityEngine;
|
|
|
|
namespace BehaviorDesigner.Runtime.Tasks.Movement
|
|
{
|
|
[HelpURLAttribute("http://www.opsive.com/assets/BehaviorDesigner/Movement/documentation.php?id=9")]
|
|
[TaskIcon("Assets/Behavior Designer Movement/Editor/Icons/{SkinColor}WanderIcon.png")]
|
|
[TaskDescription("Wander using the Unity NavMesh.")]
|
|
[TaskCategory("Movement")]
|
|
public class Wander : NavMeshMovement
|
|
{
|
|
[Tooltip("How far ahead of the current position to look ahead for a wander")]
|
|
public SharedFloat wanderDistance = 20f;
|
|
|
|
[Tooltip("The amount that the agent rotates direction")]
|
|
public SharedFloat wanderRate = 2f;
|
|
|
|
public override void OnStart()
|
|
{
|
|
base.OnStart();
|
|
SetDestination(Target());
|
|
}
|
|
|
|
public override TaskStatus OnUpdate()
|
|
{
|
|
if (HasArrived())
|
|
{
|
|
SetDestination(Target());
|
|
}
|
|
return TaskStatus.Running;
|
|
}
|
|
|
|
private Vector3 Target()
|
|
{
|
|
Vector3 vector = transform.forward + Random.insideUnitSphere * wanderRate.Value;
|
|
return transform.position + vector.normalized * wanderDistance.Value;
|
|
}
|
|
|
|
public override void OnReset()
|
|
{
|
|
wanderDistance = 20f;
|
|
wanderRate = 2f;
|
|
}
|
|
}
|
|
}
|