Legacy Documentation: Version 4.6(go to latest)
Language: English
  • C#
  • JS
  • Boo

Script language

Select your preferred scripting language. All code snippets will be displayed in this language.

NavMesh.CalculatePath

public static function CalculatePath(sourcePosition: Vector3, targetPosition: Vector3, passableMask: int, path: NavMeshPath): bool;

Parameters

sourcePosition The initial postion of the path requested.
targetPosition The final position of the path requested.
passableMask A mask specifying which NavMesh layers can be passed when calculating a path.
path The resulting path.

Returns

bool True if a path is found.

Description

Calculate a path between two points 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.

	var mesh: NavMesh;
	var target: Transform;

private var path: NavMeshPath;

function Start () { mesh.CalculatePath(transform.position, target.position, -1, path); }