![]() |
Plasma Engine
2.0
|
Computes a path through a navigation mesh. More...
#include <Navigation.h>
Public Types | |
enum class | State { Idle , StartNewSearch , InvalidCurrentPosition , InvalidTargetPosition , NoPathFound , PartialPathFound , FullPathFound , Searching } |
Public Member Functions | |
State | GetState () const |
void | Update () |
void | CancelNavigation () |
void | SetCurrentPosition (const plVec3 &vPosition) |
void | SetTargetPosition (const plVec3 &vPosition) |
const plVec3 & | GetTargetPosition () const |
void | SetNavmesh (plAiNavMesh *pNavmesh) |
void | SetQueryFilter (const dtQueryFilter &filter) |
void | ComputeAllWaypoints (plDynamicArray< plVec3 > &out_waypoints) const |
void | DebugDrawPathCorridor (const plDebugRendererContext &context, plColor tilesColor, float fPolyRenderOffsetZ=0.1f) |
void | DebugDrawPathLine (const plDebugRendererContext &context, plColor straightLineColor, float fLineRenderOffsetZ=0.2f) |
void | DebugDrawState (const plDebugRendererContext &context, const plVec3 &vPosition) const |
float | GetCurrentElevation () const |
Returns the height of the navmesh at the current position. | |
void | ComputeSteeringInfo (plAiSteeringInfo &out_info, const plVec2 &vForwardDir, float fMaxLookAhead=5.0f) |
Public Attributes | |
float | m_fPolySearchRadius = 0.5f |
float | m_fPolySearchUp = 1.5f |
float | m_fPolySearchDown = 1.5f |
Static Public Attributes | |
static constexpr plUInt32 | MaxPathNodes = 64 |
static constexpr plUInt32 | MaxSearchNodes = MaxPathNodes * 8 |
static constexpr float | c_fPathSearchBoundary = 10.0f |
Computes a path through a navigation mesh.
First call SetNavmesh() and SetQueryFilter().
When you need a path, call SetCurrentPosition() and SetTargetPosition() to inform the system of the current position and desired target location. Then call Update() once per frame to have it compute the path. Call GetState() to figure out whether a path exists. Use ComputeAllWaypoints() to get an entire path, e.g. for visualization. For steering this is not necessary. Instead use ComputeSteeringInfo() to plan the next step. Apply your steering behavior to your character as desired. Keep calling SetCurrentPosition() and SetTargetPosition() to inform the plAiNavigation of the new state, and keep calling ComputeSteeringInfo() every frame for the updated path.
If the destination was reached, a completely different path should be computed, or the current path should be canceled, call CancelNavigation(). To start a new path search, call SetTargetPosition() again (and Update() every frame).