NavMesh.CalculatePath(Vector3 sourcePosition, Vector3 targetPosition, NavMeshQueryFilter filter)
Calculate a path between two points and store the resulting path.
Parameters:
Name | Type | Description |
---|---|---|
sourcePosition | Vector3 | The initial position of the path requested. |
targetPosition | Vector3 | The final position of the path requested. |
filter | NavMeshQueryFilter | A filter specifying the cost of NavMesh areas that can be passed when calculating a path. |
Returns:
type | Description |
---|---|
boolean | True if a either a complete or partial path is found and false otherwise. |
NavMeshPath | The resulting path. |
Usage
---@type Vector3
local sourcePosition;
---@type Vector3
local targetPosition;
---@type NavMeshQueryFilter
local filter;
local val0, val1 = NavMesh:CalculatePath(sourcePosition, targetPosition, filter)
Extra Detail
Use this function to avoid gameplay delays by planning a path before it is needed. You can also use this function to check if a target position is reachable before moving the agent. This function is non-asynchronous. It performs path finding immediately which can adversely affect the frame rate when processing very long paths. It is recommended to only perform a few path finds per frame when, for example, evaluating distances to cover points.