Page 1 of 1

Enemy AI Help

PostPosted: Wed Sep 07, 2016 5:49 am
by DrakeStoel
Hi!

I've been working on programming some enemies, but have run into a couple of problems along the way.

First of all, I want my enemies to move like they're on a grid, 16x16. I have MOSTLY accomplished this. The enemy sprite moves right, left, up, or down like it should, until it just suddenly... Stops. I'm not sure why. I have it set up on a timer. Every time the timer finishes, the code randomly selects an action, moving one of the four directions, using the MoveTo function. going 16 pixels at a time. It is random when the enemy stops moving as well. Sometimes it lasts for thirty seconds, other times it gets stuck right from the get go. Can anyone help with this problem?

Also, a question about further coding. I'm hoping to be able to make my enemy lunge at my player, but only when it is in a certain proximity. I figured that the area can just be a filled region, but how can I make the enemy still always pick the direction that is closest to the player, but still stay on that four directional grid?

Thank you so much in advance! :mrgreen:

Re: Enemy AI Help

PostPosted: Thu Sep 08, 2016 2:03 am
by Zivouhr
Hopefully one of the experts will offer some advice, but I'll say that the timers aren't always reliable in Game Editor. Sometimes creating a timer within the same object executing the timer can be unreliable to the point the timer won't even start and if it does, it's delayed, so I'll have another object, like the view, create the timer within that object instead of that object creating the timer itself, and it works more reliably.

As far as the player, he needs to have an invisible box region around him (green line box for example would work, parented to the player), and anytime the enemy hits that green box (repeat on or off depending) the enemy attacks (create a command of the enemy attacking when in collision with this player box). Direction the enemy attacks separated by top, down, left or right, with variables if needed.

Some quick ideas any way. Sorry I can't offer more.

Re: Enemy AI Help

PostPosted: Fri Sep 09, 2016 12:30 am
by DrakeStoel
Ok! Thanks for the tip on timers, it works much better now! As for the movement, I'm using a Filled Region as the collision actor and have it set up to have the enemy move in towards my player. This seems to be working pretty well! It's still a little buggy, but I'm pretty certain I'll be able to figure it out.

Thanks for all your help Zivouhr! :mrgreen:

Re: Enemy AI Help

PostPosted: Sat Sep 10, 2016 10:38 pm
by Zivouhr
DrakeStoel wrote:Ok! Thanks for the tip on timers, it works much better now! As for the movement, I'm using a Filled Region as the collision actor and have it set up to have the enemy move in towards my player. This seems to be working pretty well! It's still a little buggy, but I'm pretty certain I'll be able to figure it out.

Thanks for all your help Zivouhr! :mrgreen:


You're welcome. Glad those tips gave you some ideas of how to tackle this challenge. Best of luck with the game! 8)