public Warp ( Vector3 newPosition ) : bool | ||
newPosition | Vector3 | New position to warp the agent to. |
return | bool |
NavMeshAgent agent; public void TeleportAgent() { NavMesh navMesh = NavMesh.GetNavMeshForArea(transform.position, 100.0f); // get the NavMesh Vector3 randomPos = navMesh.GetRandomPoint(); // get random position on NavMesh agent.Warp(randomPos); // teleport agent to that position }
NavMeshAgent agent; public void MoveToTarget() { Vector3 targetPos = new Vector3(10.0f, 0.0f, 10.0f); // set target position agent.Warp(targetPos); // teleport agent to target position }In this example, we simply set a target position for the agent and use Warp to instantly move the agent to that position. Overall, NavMeshAgent.Warp is a useful method in the UnityEngine.AI package library for instantly moving agents to specific positions on the NavMesh.
Warps agent to the provided position.
public Warp ( Vector3 newPosition ) : bool | ||
newPosition | Vector3 | New position to warp the agent to. |
return | bool |