PathEngine home previous: Advancing along a pathnext: Post processing the agent's path
Contents, Programmers Guide, Example Projects, Tutorials, Tutorial 3, Setting agent heading from the path

Setting agent heading from the path

By using advanceAlongPath() we get parametric movement along the path that doesn't depend on agent heading.
But we nevertheless need to set the agents heading correctly so that it looks like the agent is facing the right way for the movement along the path.

We do this with the following code:

if(path->size() >= 2)
{
// set heading from the vector for the current path section
	cPosition next_target = path->position(1);
	cPosition current = agent->getPosition();
	int32_t dx,dy;
	dx = next_target.x - current.x;
	dy = next_target.y - current.y;
	agent_heading = static_cast<float>(atan2(dx, dy));
}

Documentation for PathEngine release 6.00 - Copyright © 2002-2016 PathEnginenext: Post processing the agent's path