Enemy behaviour AI

The Logic

I need to create a simple logic enemy behavior, but got stuck at the third behavior/action and need your help.

1: all enemy that are far away which is far from 150px will move toward the player with 30px speed.
2: when each enemy reach the distance below 150px, enemy will slow down to speed 15px for 2 seconds.
3. after 2 seconds waiting, enemy will increase speed to 100px and move forward at angle of the player position, and going outside the screen. (so enemy will not follow the player, enemy keep moving fast at that determined angle)
4. enemy outside the screen will destroy/deleted.

What is the actual result

with my event the result is wrong, the enemy keep follow the player at 3 behaviour, instead of keep moving outside the screen.

Related screenshots

Hello, amar!

I think you could change this event:

For this:

thanks for your reply, but unfortunately the trigger one makes only 1 enemy moving, when I have bunch of enemy, the other enemy will stuck at place.

As you’re trying to run logic for more then a single object, you’ll need to use FOR EACH OBJECT.

This will (as the name suggests) run the logic for each of the objects chosen, otherwise the logic is only going to run on the first object.

image

1 Like

Complementing @Eiklahc answer, if there are several enemies and you will use “for each instance” so remove the trigger once, but put the action to modify the variable causing the event to occur only once for each instance. Like this:

1 Like

Thanks all for the answear, I tried repeat for each instance and it works.