xnatilespath-findingpacman

Programming AI to follow player and avoid obstacles XNA


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!


Solution

  • I see two possible choices.

    Steering Behaviours For Autonomous Characters

    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

    enter image description here

    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

    enter image description here

    Wall Following

    Perfect for PacMan

    enter image description here

    ...and many many more

    Limitations

    A* Pathfinding

    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.