I found a lot of references to the AI of the ghosts in Pacman, but none of them mentioned how the eyes find their way back to the central ghost hole after a ghost is eaten by Pacman.
In my implementation I implemented a simple but awful solution. I just hard coded on every corner which direction should be taken.
Are there any better/or the best solution? Maybe a generic one that works with different level designs?
The arcade art on the original Puck-Man designed by Namco Artist Tadashi Yamashita, portrayed him as a yellow circle with a large mouth as well as hands, feet, eyes and a long nose. The North American Pac-Man artwork by Midway, went a different way and depicted him as a yellow circle with legs and large red eyes.
Pac-Man game was chosen as the example of the shortest pathfinding by using NavMesh in Unity 3D. A* algorithm was implemented on the enemies of Pac-Man (three ghosts), which path was designed by using NavMesh concept.
During Scatter Mode, each ghost's individual target tile is placed just outside of their respective favourite corner, causing them to endlessly move in circles. The ghosts can only enter Scatter Mode a maximum of 4 times in a given life or level, at which point they'll enter Chase Mode indefinitely.
Actually, I'd say your approach is a pretty awesome solution, with almost zero-run time cost compared to any sort of pathfinding.
If you need it to generalise to arbitrary maps, you could use any pathfinding algorithm - breadth-first search is simple to implement, for example - and use that to calculate which directions to encode at each of the corners, before the game is run.
EDIT (11th August 2010): I was just referred to a very detailed page on the Pacman system: The Pac-Man Dossier, and since I have the accepted answer here, I felt I should update it. The article doesn't seem to cover the act of returning to the monster house explicitly but it states that the direct pathfinding in Pac-Man is a case of the following:
I've solved this problem for generic levels that way: Before the level starts, I do some kind of "flood fill" from the monster hole; every tile of the maze that isn't a wall gets a number that says how far it is away from the hole. So when the eyes are on a tile with a distance of 68, they look which of the neighbouring tiles has a distance of 67; that's the way to go then.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With