PathEngine home previous: Placing and moving agentsnext: Tutorial 2
Contents, Programmers Guide, Example Projects, Tutorials, Tutorial 1, Placing obstructions ‑ using collision contexts

Placing obstructions - using collision contexts

The code we use for placing obstructions looks slightly different to the code for placing the user controlled agent:

cPosition p=testbed->positionAtMouse();
if(p.cell != -1 && (agent == 0 || !agent->testCollisionDirectlyAgainstPlacedShape(obstruction_shape1, p)))
{
// place the agent if not yet placed, otherwise move to the requested position
	if(!obstruction_agent1)
	{
		obstruction_agent1 = mesh->placeAgent(obstruction_shape1,p);
		context->addAgent(obstruction_agent1);
	}
	else
		obstruction_agent1->moveTo(p);
}

Here we are not interested in checking collision with the edge of the mesh.
We allow obstructions to be placed at positions overlapping the edge of the mesh and to overlap each other.
Instead we check whether the agent will be obstructed if we place this shape at the requested position.
By preventing obstructions from being placed over the agent we guarantee that the agent will always be at an unobstructed position.

The obstructions are placed and move in the same way as the user controlled agent.
The only other difference is that when initially placed, the obstructions are added to our 'collision context'.

Collision contexts are used to manage the set of dynamic obstructions included for a given collision or pathfinding query.

For this tutorial we use a singe context that contains whichever of our two obstructions have been placed.
By applying this context when the agent is placed or moved, we prevent the agent from being placed or moved into collision with those obstructions.

Note that we could also have added the controlled agent itself to our context because agents automatically ignore collision with themselves.
This is useful when lots of agents need to share a single context for collision.

See Interface iCollisionContext for more details.


Documentation for PathEngine release 6.00 - Copyright © 2002-2016 PathEnginenext: Tutorial 2