Pathfinding

Pathfinding

This deals with the NPC’s ability to calculate the best route between two traversable points in your Panda3D environment. It requires the creation of a navigation mesh (see “Navigation Mesh” under “Mesh Generator” page), which is placed on the surface over which your NPC will be moving. The navigation mesh allows the system to recognize “traversable nodes” around the mesh, as well as areas which cannot be traversed (areas occupied by an impediment or obstacle for instance).

Using the PandAI pathfinding system:

aiBehaviors.initPathFind(string filename)

This function activates the path finding with A* for the AI Character. Filename is the name of the file that is generated by the Mesh Generator (Covered in the next section of the manual).

(Note: The file is in .csv format)

aiBehaviors.pathFindTo(NodePath np, string type)

aiBehaviors.pathFindTo(Vec3 pos, string type)

This function finds the best path via A* algorithm (with Binary Heap optimizations) for the AI Character to reach the target destination and then invokes the path follower to make the object follow the path.

It can accept both NodePath and Vec3 as input position. NodePath is used when the destination is not static. Vec3 is used when the destination is going to be static.

If the AI Character needs to pathfind continuously(say after he has finished traversing to a position, a new destination is acquired ) then input string type as “addPath” else leave as default.

addStaticObstacle(NodePath obstacle);

This function is used if the programmer wants to add Obstacles after the mesh has been generated (Say a stack of boxes fall down and blocks the way) to trigger events. It adds a static obstacle to the navigation mesh and pathfinds around it.

addDynamicObstacle(NodePath obstacle);

This functions work similar to addStaticObstacle except that in this case the obstacles can move and are not static. This is more processor heavy so if your object is not moving, use the prior instead.