| Parameter | Description |
|---|---|
| location | The position to move across the NavMesh surface. |
| destination | The world position to move the location toward. |
| areaMask | A bitmask with a value of 1 at the indexes of the areas that can be traversed, and a value of 0 for areas that aren't traversable. The default value is NavMesh.AllAreas. |
NavLocation
A new location on the NavMesh placed as closely as possible to the specified destination position.
Returns the start location when that start is inside an area that the areaMask doesn't allow.
Translates a NavMesh location to another position without losing contact with the surface.
This method returns the location on the NavMesh that is closest to the destination position and that also has a continuous connection on the NavMesh surface, through the allowed area types, all the way to the start position specified by the location parameter. If the destination position is outside the edges of the surface or of its allowed areas, this method returns a position at the edge. The search for a connected pathway is constrained to a circular area between the start and destination points. This constraint makes the operation fast, but it doesn't find a path that deviates widely to go around large obstacles.
The movement doesn't cross NavMesh Links.
You can safely call this operation while a separate pathfinding query is in progress on the same query buffer instance.
For more information about the area types that areaMask filters, refer to Areas and Costs.
Additional resources: NavWorld.MoveLocations
using UnityEngine; using UnityEngine.AI; using Unity.AI.Navigation.LowLevel; public class MoveLocationExample : MonoBehaviour { public Transform target; void Update() { using NavWorld world = NavWorld.GetDefaultWorld(); NavLocation start = world.MapLocation(transform.position, Vector3.one, 0); if (!world.IsValid(start)) return; NavLocation moved = world.MoveLocation(start, target.position, NavMesh.AllAreas); Debug.DrawLine(start.position, moved.position, Color.cyan); } }