Enemy Walking/ Attacking AI

Casper35th

  • Posts: 9
Can anyone create a behavior or two for an enemy to walk towards the main player and have an attack animation when he reaches the player? I cant seem to find what I need on Forge. PM me or just reply to this post if you can help. Thanks

Rukiri

  • Posts: 88
Learn about enemy AIs, enemy movement, distance between an object.

This has to do allot with AI so to help you first you should know about A*Pathfinding and figuring out the distance between an object and also moving from Enemy XY to the Hero's XY.

Also, you didn't specify what type of battle system this is for, action combat(seiken densetsu/zelda/mana)? or something difference.

To the one that actually does do this, this is the perfect opportunity to use events!

Casper35th

  • Posts: 9
Its a zombie side scrolling game, Id like to have them move towards the Main character and attack him, Ive got the inflict damage behavior so when they touch him he gets hurt, but having them walk and actually look like there attacking is the only thing holding me back.

Rukiri

  • Posts: 88
Ah, so predetermined than?

I'd say if the enemy is 3-5 pixels away from the enemy you should set an enemy_attack variable to true.

So if Enemy.x < Hero_Distance && Player.x { // Do main movement } else { // Do attacking stuff here }

It's pure simple and basic but I believe it's what you wanted.

Casper35th

  • Posts: 9
I have no idea how to write that in the design mode lol

Rukiri

  • Posts: 88
I'll post a demo later today.

Gryffo

  • Posts: 11
While Rukiri is working on his demo, a few tips if I may.
Looks like you already got the damage part done, so I might as well just try to elaborate on what Rukiri mentioned.

If I'm correct, what you want is an enemy behavior that moves towards the player actor only when he is close enough. That means that last zombie right before the boss wont go rampaging through the stage to eat  your brains as soon as you spawn. Additionally, you probably want zombies only to move while there is a solid path beneath their feet, much like koopas on that old snes game.

This would mean there are 2 conditions to have the enemy chasing you: a distance factor and a terrain factor. There are behaviors on the Forge I've seen myself that will let you reproduce the classic 'walk till you reach the edge, turn around, repeat' AI the koopas had back on the day. It shouldn't be much of a problem to start from that and make it the way you need it here.

As for the 'look like they're attacking or walking part', just use the set animation block. You'll have 6 animations: idle, walk and attack, mirror them for facing the opposite direction.

You can always wait/ask for someone to do it for you... but I figure this is pretty basic stuff, and there's a reward in itself if you do it yourself.

KungFuFurby

  • *
  • Posts: 487
My solution for my game was to modify the original walking behavior to include AI controls (as well as a switch). I also rigged the jumping behavior, though in your case, only walking be necessary... and slowdown. You have to rig the slowdown behavior because that handles left and right movement key detection.

I also made basic enemy AI that does determine distance from the player, though it only covers distance from left to right, not above and below.
Hi, all! I'm KungFuFurby, music composer. If you're looking for some music for your game, just PM me.
My Works List for Non-Stencyl Games
My Works List for Stencyl Games