Mykod
Mykod

Reputation: 687

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!

Upvotes: 0

Views: 1159

Answers (1)

user585968
user585968

Reputation:

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

  • Not suitable for 3D environments where an entity needs to navigate up say a set of stairs.
  • Unable to solve complex problems such as enter a building; navigate hallways; to find an exit (essentially maze solving)
  • Unable to make use of stairs or elevators to gain access to different floor levels

A* Pathfinding

More complex than the pathfinding above though it can solve many complex problems for both 2D and 3D environments.

  • Can navigate complex 3D environments of obstacles such as stairs and elevators to gain access to different floors of a building.

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.

  • Does not require tiles
  • Does require a pre-calculated invisible pathfinding mesh

Upvotes: 1

Related Questions