MoveLocation(NavLocation, Vector3, int)
Translates a NavMesh location to another position without losing contact with the surface.
Read time 2 minutesLast updated 22 days ago
Definition
- Type: Method
- Namespace: Unity.AI.Navigation.LowLevel
- Assembly: UnityEngine.AIModule
public readonly NavLocation MoveLocation(NavLocation location, Vector3 destination, int areaMask = -1)
Parameters
The position to move across the NavMesh surface.
The world position to move the location toward.
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.
Returns
Type | Description |
|---|---|
| NavLocation | A new location on the NavMesh placed as closely as possible to the specified |
Remarks
This method returns the location on the NavMesh that is closest to the 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 parameter. If the 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.
destinationlocationdestinationThe 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 filters, refer to Areas and Costs.
areaMaskAdditional Resources: NavWorld.MoveLocations
Examples
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); }}