PathEngine home previous: The path away querynext: Setting agent heading from the path
Contents, Programmers Guide, Example Projects, 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 bool advanceAlongPathWithCollisionInfo(iPath* path, float distance, const iCollisionContext* context, float& precisionX, float& precisionY, cCollidingLine& collidingLine, unique_ptr<Agent>& agent) = 0;

This function moves the agent the specified distance along the path, whilst also updating the start of the path to the agent's new position.
A collision context can be specified and in the case of a collision some information is provided about the first collision.

When approximation is required advanceAlongPathWithCollisionInfo() 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 advanceAlongPathWithCollisionInfo() for this case and it has no effect.
advanceAlongPathWithCollisionInfo() also has no effect if the path has no positions (i.e. if the query failed).


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