Advertisement

Pacman Style AI

Started by September 16, 2004 09:35 PM
4 comments, last by Jolle 20 years, 2 months ago
Greetings I am at the point in my game where I am ready to implement AI for the enemeys(Yay!!!) The game is a pacman style game where the slimes should run around and chase you. I have no idea how I should Implement this so that they arent just buzzing around in one spot because every frame a random number is chosen for the direction. How would I implement it so that they chase, guard etc? Probability Machine? Fuzzy Logic? Flocking? Thanks.
--------------------C++ Home - Check it out!Lol... - Amazing video
All those techniques are overkill. Pac-Man uses fairly simple AI.

First off, each ghost can only change direction at an intersection. They never change in the middle of the corridor, and IIRC they never even go back the way they came when they get to an intersection. So their choices are limited. I'd suggest that they simply turn whichever legal direction will head them in the general direction of Pac-Man, or at least not away from him. If you want, you can introduce a random factor into this to make some of them behave more erratically.
Advertisement
I guess I should note that its only pacman like. There is room to move up and down within the corridors. So they can technicaly do that. I'd like to add some element of AI though. I'd just like practice with it.
--------------------C++ Home - Check it out!Lol... - Amazing video
state machine!
state1: chase
state2: search
state3: run (when packman gets the superman bonus)

state2 is simple!
If you set it up so that the chance for it to continue in the same direction its going, is like 75%, then 25% to turn each way... If only one way is aviable, go this way...
If it catches you, go to state1.

state1
is also simple, find that possible move that gets you closest to the player, not in bird-distance, but in shortest way to travle to where the player is. You could use A* (A star, pathfinding algo) to find the shortest rout from aviable movemet resulst to player. This is good practice, since different forms of A* is used in almost any AI that must find the shortest way.
p.s. if the enemies are alowed to turn around in the middle of a corridor, you will have no chance to outmanover them!
If you dont succseede in a set time to catch the player, go to state2


state3
oposit to state1 :-)

This is a great way to practice game AI, this simple system is pretty hard to finetune into a great gameplay if you never toutched AI before, and remember to good enemies will kill you! :-) no fun to be dead all the time.

Also, watch the monsters in a pac-man game, and try to find rules they follow... they often dont take the best way, and they dont turn around in the middle of a corridore!
-Anders-Oredsson-Norway-
check out the pacman game on my site, & see if you like how the ghosts chase pacman around. I wrote 4 different AI modules for each of the 4 ghosts. You can't give all your slimes the same AI otherwise they'd all end up chasing your character in one big clump, rather than working together to get you & approach you from different directions. if you think I can help, email me, I'll give you some pointers.
also... since pathfinding takes some time, I implemented my AI's inside threads. otherwise... each time a slime needs a new path, you might see a frame skip... & you never want that.
Whatsoever you do, do it heartily as to the Lord, and not unto men.
the ghosts in pacman do this IIRC:
ghost 1 - chase player
ghost 2 - try to cut off player
ghost 3 - guard middle section
ghost 4 - walk randomly

This topic is closed to new replies.

Advertisement