PathEngine home previous: The path away querynext: Setting agent heading from the path
Contents, Programmers Guide, Tutorials, Tutorial 3, Advancing along a path

Advancing along a path

The segments in a path returned by a query are guaranteed to be collision free.
But in order to place an agent part way along a diagonal segment we must approximate to integer coordinates.
If we are not careful, this can put our agent inside obstructed space.
(And note that this is not an integer / floating point issue. The same problem applies when using floating point coordinates.)

The iAgent::advanceAlongPath() function takes care of this for us, and also makes sure that we get smooth movement even at low speeds.
The header for the function looks like this:

virtual iCollisionInfo* advanceAlongPath(iPath *path, float distance, iCollisionContext *context)=0;

This function moves the agent the specified distance along the path, at the same time updated the start of the path to the agent's new position.
A collision context can be specified and in the case of a collision an iCollisionInfo object is returned with information about the first collision.

When approximation is required advanceAlongPath() approximates to whichever side avoids collision.
The original path section is stored and reused for future approximations to avoid artifacts such as agents sliding along the x or y axes at slow speeds.

When an agent reaches the end of a path, the path is set accordingly - with only one position.
We can continue to call advanceAlongPath() for this case and it has no effect.
advanceAlongPath() also has no effect if the path has no positions (i.e. if the query failed).

To advance the agent along the path we simply add the following line of code:
(After checking that an agent has been placed and has a path.)

agent->advanceAlongPath(path,3,context);				

Documentation for PathEngine release 5.17 - Copyright © 2002-2008 PathEnginenext: Setting agent heading from the path