Documentation

Unity Engine


User Manual

Script Reference

Unity Engine


MapLocation(Vector3, Vector3, int, int)

Finds the closest point and PolygonId on the NavMesh for a given world position.
Read time 2 minutesLast updated 12 days ago

Definition

Warning
Deprecated. The experimental NavMeshQuery struct has been deprecated without replacement.
public NavMeshLocation MapLocation(Vector3 position, Vector3 extents, int agentTypeID, int areaMask = -1)

Parameters

position

World position for which the closest point on the NavMesh needs to be found.

extents

Maximum distance, from the specified
position
, expanding along all three axes, within which NavMesh surfaces are searched.

agentTypeID

Identifier for the agent type whose NavMesh surfaces should be selected for this operation. The Humanoid agent type exists for all NavMeshes and has an ID of 0. Other agent types can be defined manually through the Editor. A separate NavMesh surface needs to be baked for each agent type.

areaMask

Bitmask used to represent areas of the NavMesh that should (value of 1) or shouldn't (values of 0) be sampled. This parameter is optional and defaults to NavMesh.AllAreas if unspecified. Additional Resources: Areas and Costs.

Returns

Type

Description

NavMeshLocationAn object with position and valid PolygonId - when a point on the NavMesh has been found.

Remarks

The search only applies to the specified type of NavMesh surface, for one or more desired area types and is limited to within the specified search area. It does not search for positions on NavMeshLinks or OffMeshLinks.
Nearby NavMesh surfaces directly above or below the specified position are preferred. When there are none up or down within the specified search extents the surfaces closest sideways are sampled.
Additional Resources: NavMesh.SamplePosition.