Function FollowerEntity.SetDestination
Set the position in the world that this agent should move to.
void SetDestination (
float3 | destination | |
float3 | facingDirection=default |
Set the position in the world that this agent should move to.
This method will immediately try to repair the path if the agent already has a path. This will also immediately update properties like reachedDestination, reachedEndOfPath and remainingDistance. The agent may do a full path recalculation if the local repair was not sufficient, but this will at earliest happen in the next simulation step.
If you are setting a destination and want to know when the agent has reached that destination, then you could use either reachedDestination or reachedEndOfPath.
You may also set a facing direction for the agent. If set, the agent will try to approach the destination point with the given heading. reachedDestination and reachedEndOfPath will only return true once the agent is approximately facing the correct direction. The MovementSettings.follower.leadInRadiusWhenApproachingDestination field controls how wide an arc the agent will try to use when approaching the destination.
The following video shows three agents, one with no facing direction set, and then two agents with varying values of the lead in radius.
IEnumerator Start () {
ai.SetDestination(somePoint, Vector3.right);
// Wait until the AI has reached the destination and is rotated to the right in world space
while (!ai.reachedEndOfPath) {
yield return null;
}
// The agent has reached the destination now
}