Basic Top Down Shooter Buddy AI

by Nighthawk

Posted on June 06, 2008 at 8:31 AM

Obelisk made a blog entry the other day, asking about this:

You have a character. Whenever you click on him, he'll become selected. You'll click somewhere on the screen, and he'll move to that spot. He avoids running into buildings and whatnot. Whenever he's not told to go anywhere, he just follows another character controlled with WASD. Whenever he comes across an enemy, he shoots at it. Pathfinding would be direly important, if I knew how to do it then I wouldn't even be asking someone else for this.

I hope this example helps him, along with anyone else who may be curious as to a simple but effective way to do this.

WASD: Move
Left Click: Shoot
Right Click: Set/Remove Destination point for buddy

This example is throughly commented, and includes some sprites and music which you MAY use if you give me credit for them. I don't mind if you copy and paste bits of code without crediting me, but if you use this as the main foundation for your game, please give me credit for it. Enjoy!

This example requires GM7 Pro.

Fabio commented June 06, 2008 at 4:27 PM
Great work. There are some flaws, like letting the enemy AI shoot at a wall while you direct your buddy to destroy them, but that's not what this example was made for. Good pathfinding, does exactly what it is supposed to. 10/10.
Fylus commented June 06, 2008 at 5:03 PM
i really like it. its really effective and its pretty fun :P 10/10
Obelisk commented June 06, 2008 at 6:13 PM
It's way off and Fabio's flaws need to be taken care of. Also you didn't really do the selection system in the request.

The AI wasn't exactly smart either, I made sort of a coil pattern with the blocks and whenever I wanted him to get out, he would run around in circles.

Thank you very much though, 10/10
Cpsgames commented June 06, 2008 at 10:39 PM
Executed nicely, 10/10
Castypher commented June 07, 2008 at 6:22 AM
It was pretty polished and looked like it was all ready to be used, but I found some tiny annoying flaws.

First of all, AI shouldn't shoot at walls, even if there's an enemy behind it. It's pointless. That's fixed with easy collision checking, for example, collision_line.
I noticed your code was a bit odd. You could've used repeat(x), and didn't. That shouldn't affect your rating, but I figured I'd bring it up.
Finally, motion planning is good, but as Zane said, you might want to make some different movement patterns.

It's not bad, and it follows Zane's specifications pretty closely, so I'd say it meets the objective. 10/10 is a bit overrated, I think.

svf commented June 10, 2008 at 12:47 AM
Smoothly Made.
Really nice
Nighthawk commented June 10, 2008 at 5:07 PM
Thanks for the positive feedback (and the fancy new badge :D) guys! I should take example requests more often. ^_^
maxiuim33 commented June 12, 2008 at 12:06 AM
how do u download gamemaker?
Nighthawk commented June 12, 2008 at 8:33 AM
Here's a strange place to be asking that... But meh, here ya go:
Xxypher commented July 12, 2008 at 5:01 PM
Nice! Better than my AI, but not by much.
xskullsgames commented August 18, 2008 at 11:35 PM
how do u download gamemaker?
Wtf?, You should have it before joining lol.

Oh yeah really nice 6/10 (j/k)
hahaha 10/10