Path Finding and Path Following

The path finding and path following system is the highest-level service provided by Autodesk Navigation. It applies many other subsystems provided by the toolbox layer, including the query system.

The system is based around the Bot class and its sub-components, which manage many of the complexities involved in providing pathfinding for characters in a three-dimensional game, including:

Each NPC that you want to use the Autodesk Navigation path finding and path following system should have its own instance of the Bot class. If you have already followed the steps in the integration tutorial (see Integrating Navigation into your Game Engine), you have already written a minimal amount of code to initialize, update and destroy a Bot for a character in your game.

The path finding and following process

Each instance of the Bot class uses the same general process for finding and following paths, outlined in the following sections.

Stage 1. Getting an initial Path

The first step in the path following system is to compute an initial path through the NavData, that connects a starting point (typically the current position of the Bot) to a desired destination. This initial path is represented by an instance of the Path class, a static immutable structure that consists of nodes connected by edges.

For example, in the image below, the yellow Bot has planned a path to a destination on the rooftop. The path goes through the NavMesh on the ground, follows a NavGraph edge that connects the ground to the rooftop, then has a final segment on the rooftop from the end of the NavGraph edge to the destination.

By default, every Bot has access to a query that can compute a Path, which it retrieves from an object called its NavigationProfile. When you want to calculate a new path, you use the Bot API to request the path calculation, and the Bot carries out the query asynchronously during the next update.

There are several different ways to request your Bot to calculate the path; or, you can provide your Bot with a pre-calculated path. For details, see Getting a Static Path.

Stage 2. Creating the LivePath

Once the Bot has successfully calculated a Path, or when you inject your own Path, the path following system analyzes the new path and builds a new structure called the LivePath from it. The LivePath is a dynamic structure that maintains several important items of contextual information about the path and the state of the Bot's path following process, including a list of PathEvents that you can browse at any time to retrieve information about the path. You can use these PathEvents to scan along the path for upcoming transitions to different terrain types, smart objects, or invalid areas.

For example, in the image below, the flags mark transition events in the LivePath: each time the path crosses into an area with a different NavTag, and at the start and end of the NavGraph edge.

For details on these PathEvents and how you can interact with them, see Monitoring PathEvents.

Stage 3. Following the LivePath

In each frame, the Bot calls a Trajectory object to determine what movement it should make in the current frame. The Trajectory is responsible for evaluating the current conditions of the Bot and its path, and taking into account any other influences such as moving obstacles that may produce collisions. Based on these factors, and on a set of configuration parameters that control the character's locomotion, it produces a recommended velocity for the character to pursue in the current frame.

By default, Bots are set up to use in instance of the Trajectory class. This implementation of Trajectory can use either of two different strategies for computing the final velocity:

You determine which trajectory mode is used at the time you initialize your Bot, and you can change on the fly at any time after initialization. See also Customizing Path Following.

Regardless of which strategy the Trajectory is currently using in any given frame, it may apply the following conditions:

The classes involved in the trajectory and dynamic avoidance systems contain a wide range of configuration parameters that you can tune for each character. See also Customizing Path Following.

Stage 4. Retrieving and applying results

To retrieve the final result of the path following system at each frame, you need to access BotOutput as shown in the following example:

m_velocity = m_navBot->GetBotOutput().m_outputVelocity();

It is your responsibility to apply this velocity to your game character, subject to any additional constraints implied by your animation or physics systems.

Autodesk Navigation does not make any assumption on how your game entity moves and steers in your game. Your characters can be completely animation driven, or completely physics driven. This is why the Bot does not move itself automatically; you interpret the suggested velocity produced by the path following system, adapt it to your needs, and inform the Bot of the actual changes in position and velocity that you apply to your character.

The path following system does not expect the character to be in the position it predicts at all times. Several things may explain why your game entity may move differently:

In most cases the Bot will be able to carry on following the path transparently, regardless of minor differences between the suggested velocity computed by the path following system and the actual position and velocity, or events in the game that push it off course.

However, if significant difference can occur in your game, such as a character being pushed off a cliff, it is a good idea to test the validity of the character's progress along its path at each frame. If the character's position on its path becomes unreachable and a new one cannot be determined, you may want to re-calculate a new path to the destination. See also Monitoring Path Following.

Monitoring

As your characters follow their paths, you may need to respond to many different kinds of events. It is your responsibility to watch for events that you want to respond to, and handle them appropriately when they do arise.

For a detailed discussion, see Monitoring Path Following.