Original Post
Hi I am currently create a PacMan clone for the fun off it, and I've encountered a problem on how to make the Ghosts follow the path returned by the A* Path Finder. Now the Path returned consists of a whole lot of - std::pair< Node, Action> where Node is the next Node the Ghost should go to and Action is the Action it can use to get there. I'm using Box2D as a physics engine (I know it would be a lot easier without it, just humour me ..) The First Method that I tried was that there was a class GhostAction which was basically this - (I love version controll :-) ) Then when the path was returned I would simple transverse the list and apply the required velocity for the required amount of time. But that did not work as planned as 1. The GhostNode class was implemented with int and not floats (The world is continuous ) so certain rounding off occured and the Ghost often got stuck. 2. Same as above ^^ The second approach was that I used a Dir enum as the GhostAction and the Ghost would move in that direction until it reached the next point or went ahead. This approach doesn't work for high speeds though. Does any one have any idea as to how I could implement some way to transverse the Path ?
class GhostAction
{
public :
float fSpeed;
GhostAction(float dist=1.0)
{
//As speed = dist/time
fSpeed = 5.00;
time = 1/fSpeed;
vel.SetZero();
}
virtual ~GhostAction() {}
float time;
b2Vec2 vel;
void left() { vel.Set( -fSpeed, 0.0f ); }
void right(){ vel.Set( +fSpeed, 0.0f ); }
void up(){vel.Set( 0.0f, -fSpeed); }
void down(){ vel.Set( 0.0f, +fSpeed); }
};