A* Pathfinding Project  3.8.5
The A* Pathfinding Project for Unity 3D
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Properties Events Macros Groups Pages
RichFunnel Class Reference

Public Types

enum  FunnelSimplification { None, Iterative, RecursiveBinary, RecursiveTrinary }
 Different algorithms for simplifying a funnel corridor using linecasting. More...
 

Public Member Functions

 RichFunnel ()
 
void BuildFunnelCorridor (List< GraphNode > nodes, int start, int end)
 Build a funnel corridor from a node list slice.
 
Vector3 ClampToNavmesh (Vector3 position)
 Clamps the position to the navmesh and repairs the path if the agent has moved slightly outside it.
 
bool FindNextCorners (Vector3 origin, int startIndex, List< Vector3 > funnelPath, int numCorners, out bool lastCorner)
 
void FindWalls (List< Vector3 > wallBuffer, float range)
 Fill wallBuffer with all navmesh wall segments close to the current position.
 
RichFunnel Initialize (RichPath path, NavGraph graph)
 Works like a constructor, but can be used even for pooled objects.
 
override void OnEnterPool ()
 
void SimplifyPath (IRaycastableGraph graph, List< GraphNode > nodes, int start, int end, List< GraphNode > result, Vector3 startPoint, Vector3 endPoint)
 Simplifies a funnel path using linecasting.
 
Vector3 Update (Vector3 position, List< Vector3 > buffer, int numCorners, out bool lastCorner, out bool requiresRepath)
 Find the next points to move towards and clamp the position to the navmesh.
 
void UpdateFunnelCorridor (int splitIndex, TriangleMeshNode prefix)
 Split funnel at node index splitIndex and throw the nodes up to that point away and replace with prefix.
 

Static Public Member Functions

static void SimplifyPath2 (IRaycastableGraph rcg, List< GraphNode > nodes, int start, int end, List< GraphNode > result, Vector3 startPoint, Vector3 endPoint)
 
static void SimplifyPath3 (IRaycastableGraph rcg, List< GraphNode > nodes, int start, int end, List< GraphNode > result, Vector3 startPoint, Vector3 endPoint, int depth=0)
 

Public Attributes

Vector3 exactEnd
 
Vector3 exactStart
 
FunnelSimplification funnelSimplificationMode = FunnelSimplification.Iterative
 How to post process the funnel corridor.
 

Properties

TriangleMeshNode CurrentNode [get]
 

Private Member Functions

bool CheckForDestroyedNodes ()
 True if any node in the path is destroyed.
 
bool ClampToNavmeshInternal (ref Vector3 position)
 Searches for the node the agent is inside.
 
void FindWalls (int nodeIndex, List< Vector3 > wallBuffer, Vector3 position, float range)
 

Private Attributes

int checkForDestroyedNodesCounter
 
int currentNode
 
Vector3 currentPosition
 
NavGraph graph
 
readonly List< Vector3 > left
 
List< TriangleMeshNodenodes
 
RichPath path
 
readonly List< Vector3 > right
 
int[] triBuffer = new int[3]
 

Member Enumeration Documentation

Different algorithms for simplifying a funnel corridor using linecasting.

This makes the most sense when using tiled navmeshes. A lot of times, the funnel corridor can be improved by using funnel simplification. You will have to experiment and see which one of these give the best result on your map. In my own tests, iterative has usually given the best results, closesly followed by RecursiveTrinary which was the fastest one, recursive binary came last with both the worst quality and slowest execution time. But on other maps, it might be totally different.

Enumerator:
None 
Iterative 
RecursiveBinary 
RecursiveTrinary 

Constructor & Destructor Documentation

Member Function Documentation

void BuildFunnelCorridor ( List< GraphNode nodes,
int  start,
int  end 
)

Build a funnel corridor from a node list slice.

The nodes are assumed to be of type TriangleMeshNode.

Parameters
nodesNodes to build the funnel corridor from
startStart index in the nodes list
endEnd index in the nodes list, this index is inclusive
bool CheckForDestroyedNodes ( )
private

True if any node in the path is destroyed.

Vector3 ClampToNavmesh ( Vector3  position)

Clamps the position to the navmesh and repairs the path if the agent has moved slightly outside it.

You should not call this method with anything other than the agent's position.

bool ClampToNavmeshInternal ( ref Vector3  position)
private

Searches for the node the agent is inside.

This will also clamp the position to the navmesh and repair the funnel cooridor if the agent moves slightly outside it.

Assumes the check for if the position is inside nodes[currentNode] has already been done.

Returns
True if nodes along the path have been destroyed so that a path recalculation is required
bool FindNextCorners ( Vector3  origin,
int  startIndex,
List< Vector3 >  funnelPath,
int  numCorners,
out bool  lastCorner 
)
void FindWalls ( List< Vector3 >  wallBuffer,
float  range 
)

Fill wallBuffer with all navmesh wall segments close to the current position.

A wall segment is a node edge which is not shared by any other neighbour node, i.e an outer edge on the navmesh.

void FindWalls ( int  nodeIndex,
List< Vector3 >  wallBuffer,
Vector3  position,
float  range 
)
private
RichFunnel Initialize ( RichPath  path,
NavGraph  graph 
)

Works like a constructor, but can be used even for pooled objects.

Returns this for easy chaining

override void OnEnterPool ( )
virtual

Implements RichPathPart.

void SimplifyPath ( IRaycastableGraph  graph,
List< GraphNode nodes,
int  start,
int  end,
List< GraphNode result,
Vector3  startPoint,
Vector3  endPoint 
)

Simplifies a funnel path using linecasting.

Running time is roughly O(n^2 log n) in the worst case (where n = end-start) Actually it depends on how the graph looks, so in theory the actual upper limit on the worst case running time is O(n*m log n) (where n = end-start and m = nodes in the graph) but O(n^2 log n) is a much more realistic worst case limit.

Requires graph to implement IRaycastableGraph

static void SimplifyPath2 ( IRaycastableGraph  rcg,
List< GraphNode nodes,
int  start,
int  end,
List< GraphNode result,
Vector3  startPoint,
Vector3  endPoint 
)
static
static void SimplifyPath3 ( IRaycastableGraph  rcg,
List< GraphNode nodes,
int  start,
int  end,
List< GraphNode result,
Vector3  startPoint,
Vector3  endPoint,
int  depth = 0 
)
static
Vector3 Update ( Vector3  position,
List< Vector3 >  buffer,
int  numCorners,
out bool  lastCorner,
out bool  requiresRepath 
)

Find the next points to move towards and clamp the position to the navmesh.

Parameters
positionThe position of the agent.
bufferWill be filled with up to numCorners points which are the next points in the path towards the target.
numCornersSee buffer.
lastCornerTrue if the buffer contains the end point of the path.
requiresRepathTrue if nodes along the path have been destroyed and a path recalculation is necessary.
Returns
The position of the agent clamped to make sure it is inside the navmesh.
void UpdateFunnelCorridor ( int  splitIndex,
TriangleMeshNode  prefix 
)

Split funnel at node index splitIndex and throw the nodes up to that point away and replace with prefix.

Used when the AI has happened to get sidetracked and entered a node outside the funnel.

Member Data Documentation

int checkForDestroyedNodesCounter
private
int currentNode
private
Vector3 currentPosition
private
Vector3 exactEnd
Vector3 exactStart
FunnelSimplification funnelSimplificationMode = FunnelSimplification.Iterative

How to post process the funnel corridor.

NavGraph graph
private
readonly List<Vector3> left
private
List<TriangleMeshNode> nodes
private
RichPath path
private
readonly List<Vector3> right
private
int [] triBuffer = new int[3]
private

Property Documentation

TriangleMeshNode CurrentNode
get

The documentation for this class was generated from the following file: