Enemy Facing Player SOLVED!

I have multiple enemies of the same object how do i make them face me even if i stand in the middle?

for example my player is in the middle and there are 5 enemys on each side
if i stand in the middle they all flip to 1 side and i dont know how to fix that

this is my code

Hey,

The condition “player distance to clone” doesn’t specify on which side the object is on relative to the player, it only checks the distance. You’ll need to add a condition to check the X position of the object if it’s > or < than the player. Also why are you using the raycast condition? I don’t see a use for it.

The event would be like this:

Repeat for each Clone

  • Player distance to Clone is below Player.Stealth
    [Sub events]
    – X pos of Clone > Player.X() → Simulate Left & Flip
    – X pos of Clone < Player.X() → Simulate Right & No Flip

Also, the first 2 flip events should be after the repeat event and not before it.

Hey i it is the same code but this still hapens
image
they all flip to the same side


also i used the raycast to make it so if they are more then 500 pixels away they dont go to me do you have another solution for that?

What is the value of Player.Stealth?

Try moving the bottom events inside the for each event.

its 1500
postneedstobe20characterslong

Player.Stealth is 1500

little late reply but that doesnt work either

It looks like it should be working just based on these events. Are there any other events that could be affecting their movement? When you say it doesn’t work, do you mean that they all go in the same direction as before?

when i stand in the middle of 5 enemies they all face 1 way

there are no other movement events

They get spawned by this event maybe that is causing trouble

Weird, they should go in different directions… actually, it looks like you have the left and right mixed up. If you want them to chase the player then they should go RIGHT when their X position is less than player and LEFT when their X position is greater.

I don’t see anything in your second screenshot that would affect their movement either. Can you show a video of it happening? Or even upload the project file so we could look through it?

I can try to make a video on thursday

You have couple mistakes in the last screenshot you shared.

  • in the first event, you’re checking for a link between clone_2 and clone2_gun in the sub-event, but there would be no link since clone_2 has just been created.

  • in the 3rd event, I see you want to create a gun for each clone_2, but you can’t use “trigger once” inside a for each event.

Instead what you want to do is create the gun and link it to clone_2 in the 1st event (same as the health bar)

Remove the last event (for each) and put the last event (gun is linked to clone → change position of the gun) in the other for each clone_2 event that you used to flip the objects. It’s better to use the same for each event if possible.

Alright I’ll try it Thursday

no i wanted them to move away from the player
but it works now
image

image
image
image

now they are always facing me
(i tried to upload a video but idk how)

thank you insein and magicsofa for helping