PathEngine home previous: The shortest path querynext: Advancing along a path
Contents, Programmers Guide, Example Projects, Tutorials, Tutorial 3, The path away query

The path away query

This query returns the shortest unobstructed path for an agent from a start position to outside a given area.
The area is defined by a horizontal (and axis aligned) square projected onto the mesh, and specified by a central position plus a radius.

Where there is overlapping geometry the square only affects parts of the mesh that are connected through the mesh within the bounds of the square.
This is the same paradigm as for obstacles that overlap the edge of the mesh.
(See The PathEngine Movement Model.)
You can think of this as a fill operation starting at the central position and terminating at the bounds of the square.

In this diagram, the agent is already outside the area, so a path with 1 position is returned.

But if the central position is moved a little to the left the agent is now inside the area.

Again, calling the query is pretty simple:

if(testbed->getRightMouseState())
{
// path away from position under mouse
	path = nullptr;
	cPosition awayfrom = testbed->positionAtMouse();
	if(awayfrom.cell != -1)
	{
		auto imaginary_agent = mesh->placeAgent(*obstruction_shape1, awayfrom);
		context->addAgent(*imaginary_agent);
		path = agent->findPathAway(context, awayfrom, 500);
	}
}

Note that we added an 'imaginary' agent to the context, placed over the 'awayfrom' position.
This is useful for example for runaway behaviours.
In this case the 'awayfrom' position represents a source of danger.
An imaginary agent like this can be used to prevent the path going too close to a given position.
The size and shape of the imaginary agent can be adjusted for optimium behaviour.
In this case we just reused the obstruction 1 shape for simplicity.

Again, we pass our context into the query so that any obstacles that have been placed will automatically be taken into account by the query.


Documentation for PathEngine release 6.04 - Copyright © 2002-2024 PathEnginenext: Advancing along a path