dtPathCorridor

Represents a dynamic polygon corridor used to plan agent movement.

Windows
MacOS
Linux

References

Module

Navmesh

Header

/Engine/Source/Runtime/Navmesh/Public/DetourCrowd/DetourPathCorridor.h

Include

#include "DetourCrowd/DetourPathCorridor.h"

Syntax

class dtPathCorridor

Remarks

Represents a dynamic polygon corridor used to plan agent movement. ,

The corridor is loaded with a path, usually obtained from a dtNavMeshQuery::findPath() query. The corridor is then used to plan local movement, with the corridor automatically updating as needed to deal with inaccurate agent locomotion.

Example of a common use case:

Construct the corridor object and call init() to allocate its path buffer.

Obtain a path from a dtNavMeshQuery object.

Use reset() to set the agent's current position. (At the beginning of the path.)

Use setCorridor() to load the path and target.

Use findCorners() to plan movement. (This handles dynamic path straightening.)

Use movePosition() to feed agent movement back into the corridor. (The corridor will automatically adjust as needed.)

If the target is moving, use moveTargetPosition() to update the end of the corridor. (The corridor will automatically adjust as needed.)

Repeat the previous 3 steps to continue to move the agent.

The corridor position and target are always constrained to the navigation mesh.

One of the difficulties in maintaining a path is that floating point errors, locomotion inaccuracies, and/or local steering can result in the agent crossing the boundary of the path corridor, temporarily invalidating the path. This class uses local mesh queries to detect and update the corridor as needed to handle these types of issues.

The fact that local mesh queries are used to move the position and target locations results in two beahviors that need to be considered:

Every time a move function is used there is a chance that the path will become non-optimial. Basically, the further the target is moved from its original location, and the further the position is moved outside the original corridor, the more likely the path will become non-optimal. This issue can be addressed by periodically running the optimizePathTopology() and optimizePathVisibility() methods.

All local mesh queries have distance limitations. (Review the dtNavMeshQuery methods for details.) So the most accurate use case is to move the position and target in small increments. If a large increment is used, then the corridor may not be able to accurately find the new location. Because of this limiation, if a position is moved in a large increment, then compare the desired and resulting polygon references. If the two do not match, then path replanning may be needed. E.g. If you move the target, check getLastPoly() to see if it is the expected polygon.

Constructors

Name Description

Public function

dtPathCorridor()

Destructors

Name Description

Public function

~dtPathCorridor()

Functions

Name Description

Public function Const

bool

 

canMoveOverOffmeshConnection

(
    dtPolyRef offMeshConRef,
    dtPolyRef* refs,
    const float* agentPos,
    float* startPos,
    float* endPos,
    dtNavMeshQuery* navquery
)

[UE4] check if offmesh connection can be traversed, but don't modify corridor yet

Public function

int

 

findCorners

(
    float* cornerVerts,
    unsigned char* cornerFlags,
    dtPolyRef* cornerPolys,
    const int maxCorners,
    dtNavMeshQuery* navquery,
    const dtQueryFilter* filter,
    float pathOffsetDistance,
    float earlyReachDistance,
    bool bAllowEarlyReach
)

Finds the corners in the corridor from the position toward the target.

Public function

bool

 

fixPathStart

(
    dtPolyRef safeRef,
    const float* safePos
)

Public function Const

dtPolyRef

 

getFirstPoly()

The polygon reference id of the first polygon in the corridor, the polygon containing the position.

Public function Const

dtPolyRef

 

getLastPoly()

The polygon reference id of the last polygon in the corridor, the polygon containing the target.

Public function Const

const float ...

 

getNextFixedCorner()

Public function Const

const float ...

 

getNextFixedCorner2()

Public function Const

const dtPoly...

 

getPath()

The corridor's path.

Public function Const

int

 

getPathCount()

The number of polygons in the current corridor path.

Public function Const

const float ...

 

getPos()

Gets the current position within the corridor. (In the first polygon.)

Public function Const

float

 

getSegmentAngle()

Public function Const

const float ...

 

getTarget()

Gets the current target within the corridor. (In the last polygon.)

Public function Const

bool

 

hasNextFixedCorner()

Public function Const

bool

 

hasNextFixedCorner2()

Public function

bool

 

init

(
    const int maxPath
)

Allocates the corridor's path buffer.

Cannot be called more than once.

Public function

bool

 

isValid

(
    const int maxLookAhead,
    dtNavMeshQuery* navquery,
    const dtQueryFilter* filter
)

Checks the current corridor path to see if its polygon references remain valid.

Public function

bool

 

moveOverOffmeshConnection

(
    dtPolyRef offMeshConRef,
    dtPolyRef* refs,
    const float* agentPos,
    float* startPos,
    float* endPos,
    dtNavMeshQuery* navquery
)

Public function

bool

 

movePosition

(
    const float* npos,
    dtNavMeshQuery* navquery,
    const dtQueryFilter* filter
)

Moves the position from the current location to the desired location, adjusting the corridor as needed to reflect the change.

Public function

void

 

moveTargetPosition

(
    const float* npos,
    dtNavMeshQuery* navquery,
    const dtQueryFilter* filter
)

Moves the target from the curent location to the desired location, adjusting the corridor as needed to reflect the change.

Public function

bool

 

optimizePathTopology

(
    dtNavMeshQuery* navquery,
    const dtQueryFilter* filter
)

Attempts to optimize the path using a local area search.

Public function

bool

 

optimizePathVisibility

(
    const float* next,
    const float pathOptimizationRange,
    dtNavMeshQuery* navquery,
    const dtQueryFilter* filter
)

Attempts to optimize the path if the specified point is visible from the current position.

Public function

void

 

pruneOffmeshConenction

(
    dtPolyRef offMeshConRef
)

[UE4] remove offmesh connection from corridor

Public function

void

 

reset

(
    dtPolyRef ref,
    const float* pos
)

Resets the path corridor to the specified position.

Public function

void

 

setCorridor

(
    const float* target,
    const dtPolyRef* polys,
    const int npath
)

Loads a new path and target into the corridor.

Public function

void

 

setEarlyReachTest

(
    bool enable
)

Public function

bool

 

trimInvalidPath

(
    dtPolyRef safeRef,
    const float* safePos,
    dtNavMeshQuery* navquery,
    const dtQueryFilter* filter
)

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