Skip to content

NavMeshAgent.calculatePath

Wyatt Gillette edited this page Oct 28, 2021 · 2 revisions

Declaration

public boolean calculatePath(Vector3f targetPosition, NavMeshPath path);

Parameters

targetPosition The final position of the path requested.
path The resulting path.

Returns

boolean True if a path is found.

Description

Calculate a path to a specified point and store the resulting path. This function can be used to plan a path ahead of time to avoid a delay in gameplay when the path is needed. Another use is to check if a target position is reachable before moving the agent.

Vector3f targetPos;
NavMeshAgent agent;

NavMeshPath navPath = new NavMeshPath();
agent.calculatePath(targetPos, navPath);

if (navPath.getStatus() == NavMeshPathStatus.PathComplete) {
    agent.setPath(navPath);
}
Clone this wiki locally