How to make all enemies react different towards my player

when my player is close to the enemy, all the enemies turn and shoot at my player at the same time, how can I make the first enemy turn and shoot at my player first, when my player is close to the first enemy.

my enemy name is (nme cube)
the name of my object that shoot the bullet is (muzzle)

here the youtube video name: GDevelop: how to make all enemies react different towards my player

if i understand well.You need the condition:“pick up closest object” to your player.

The first issue is the use of the “repeat for each instance” events:

The first repeat means all the subevents are dealing with just one nme_cube at a time. So that third repeat events and it’s first condition are completely redundant.

Secondly, you should be doing the condition first in a separate event and then repeating as a subevent of that event. You first filter or reduce the number of objects, then run the repeat over them.

Thirdly, the condition in the second and first condition in the third repeat events have already been met by the condition in the first repeat event. So again, they are redundant.

And as @bandi6891 wrote, you’ll need to use the “pick closest object” or “pick random object” after the distance check between player2 and nme_cube. So you want something like:

image

No need to repeat over each nme_cube object.


I’m not sure how you want to select the muzzle to rotate. Does a each nme_cube have a muzzle or are they independent?

Also, these actions:
image

will keep the muzzle animation at the second frame - the first frame is frame 0. If you change animation, and the sprite is already playing that animation, it will just carry on. If the sprite had a different animation playing, then it will start the new animation from the first frame.


Finally, these conditions:
image

mean that the same bullet has to be in collision with a nme_cube and a muzzle for the actions to be processed. Is this what you are after?