I need to make a pacman game and I'm having trouble making the code for the ghosts to follow pacman and avoid the obstacles. Can somebody give me some tips on what's the best way to do it in XNA? I've heard about pathfinding but my game does not use tiles!
Thank you!
I see two possible choices.
This work by Craig Reynolds breaks down behaviours into a series of modules that may be used singularly or together to form complex behaviours. Each module is based on a steering concept where an entity either steers towards or away from a target
Seek and Flee
Useful for moving towards a known point
Pursue and Evade
Pursue is a more advanced than the prior seek by taking into account the current velocity of the target so it can predict where it will be in the future
Wall Following
Perfect for PacMan
...and many many more
Limitations
More complex than the pathfinding above though it can solve many complex problems for both 2D and 3D environments.
However A* might be overkill for a simple 2D Maze game like PacMan where Steering Behaviours can adequately implement.
Please refer to Implementing the A* Pathfinding Algorithm in XNA for an actual implementation of A* in XNA.