dtNavMeshQuery::raycast

Casts a 'walkability' ray along the surface of the navigation mesh from the start position toward the end position.

Windows
MacOS
Linux

References

Module

Navmesh

Header

/Engine/Source/Runtime/Navmesh/Public/Detour/DetourNavMeshQuery.h

Include

#include "Detour/DetourNavMeshQuery.h"

Source

/Engine/Source/Runtime/Navmesh/Private/Detour/DetourNavMeshQuery.cpp

Syntax

dtStatus raycast
(
    dtPolyRef startRef,
    const float * startPos,
    const float * endPos,
    const dtQueryFilter * filter,
    float * t,
    float * hitNormal,
    dtPolyRef * path,
    int * pathCount,
    const int maxPath
) const

Remarks

Casts a 'walkability' ray along the surface of the navigation mesh from the start position toward the end position.

This method is meant to be used for quick, short distance checks.

If the path array is too small to hold the result, it will be filled as far as possible from the start postion toward the end position.

Using the Hit Parameter (t)

If the hit parameter is a very high value (FLT_MAX), then the ray has hit the end position. In this case the path represents a valid corridor to the end position and the value of `hitNormal_ is undefined.

If the hit parameter is zero, then the start position is on the wall that was hit and the value of `hitNormal_ is undefined.

If 0 < t < 1.0 then the following applies:

distanceToHitBorder=distanceToEndPosition*thitPoint=startPos+(endPos-startPos)*t

Use Case Restriction

The raycast ignores the y-value of the end position. (2D check.) This places significant limits on how it can be used. For example:

Consider a scene where there is a main floor with a second floor balcony that hangs over the main floor. So the first floor mesh extends below the balcony mesh. The start position is somewhere on the first floor. The end position is on the balcony.

The raycast will search toward the end position along the first floor mesh. If it reaches the end position's xz-coordinates it will indicate FLT_MAX (no wall hit), meaning it reached the end position. This is one example of why this method is meant for short distance checks.

Returns

The status flags for the query.

Parameters

Parameter

Description

startRef

The reference id of the start polygon.

startPos

A position within the start polygon representing the start of the ray. [(x, y, z)]

endPos

The position to cast the ray toward. [(x, y, z)]

t

The hit parameter. (FLT_MAX if no wall hit.)

hitNormal

The normal of the nearest wall hit. [(x, y, z)]

filter

The polygon filter to apply to the query.

path

The reference ids of the visited polygons. [opt]

pathCount

The number of visited polygons. [opt]

maxPath

The maximum number of polygons the path array can hold.

walkableArea

Specific area that can be visited or 255 to skip it and test all areas.

Help shape the future of Unreal Engine documentation! Tell us how we're doing so we can serve you better.
Take our survey
Dismiss