Skip to content

Api > NavMesh > Raycast()


NavMesh.Raycast(Vector3 sourcePosition, Vector3 targetPosition, NavMeshQueryFilter filter)⚓︎

Traces a line between two positions on the NavMesh, subject to the constraints defined by the filter argument. The line is terminated on outer edges or a non-passable area.

Parameters:⚓︎

Name Type Description
sourcePosition Vector3 The origin of the ray.
targetPosition Vector3 The end of the ray.
filter NavMeshQueryFilter A filter specifying which NavMesh areas can be passed when tracing the ray.

Returns:⚓︎

type Description
boolean True if the ray is terminated before reaching target position. Otherwise returns false.
NavMeshHit properties of the ray cast resulting location.

Usage⚓︎

---@type Vector3
local sourcePosition;

---@type Vector3
local targetPosition;

---@type NavMeshQueryFilter
local filter;


local val0, val1 = NavMesh:Raycast(sourcePosition, targetPosition, filter)
t. If the ray hits a NavMesh boundary, the function returns true and the hit data is filled. If the path from the source to target is unobstructed, the function returns false. If the raycast terminates on an outer edge, hit.mask is 0; otherwise it contains the area mask of the blocking polygon. This function can be used to check if an agent can walk unobstructed between two points on the NavMesh. For example if you character has an evasive dodge move which needs space, you can shoot a ray from the characters location to multiple directions to find a spot where the character can dodge to.