Thread: Is there a way to make enemies only attack when they’re facing the player object?

1. Is there a way to make enemies only attack when they’re facing the player object?

Something I was wondering. I made enemies in my app shoot when the player character overlaps an invisible active object, but it’ll only shoot in the direction it’s facing. Any way to only make it shoot at the player object when it’s facing it?

2. If you are using the built in "Launch an object" then you can select "Launch in direction of..." and then pick the player object. It will then always shoot towards the player.

3. Test the position of the enemy relative to the player & its direction. Something like this:

y position of Enemy <= y position of player + 5 (They're on the same platform)
y.position of Enemy >= y position of player - 5 (They're on the same platform)
+
x position of Enemy >= x position of player - 100 (Enemy is to the left of the player and within range)
x position of Enemy <= x position of player (Enemy is to the left of the player)
+
Enemy direction = Right (Enemy can see the player)
= Then Shoot

4. For clarification, I insert all the X and Y statements in the same event where the player overlaps the trigger, right?

5. If the player overlaps the trigger - turn a flag on for the player - let's say flag 1

Then start a new event

If flag 1 of player is on
+ all the x, y & direction stuff
= then shoot

6. I tried that and it's not working. It's in the global events.

7. You just have the enemy direction set wrong - yours is opposite to what it should be.

Change it so the enemy is looking right.

8. I tried that. It doesn't work. I even added one so that there's one for looking both directions. That didn't work.

9. Attached is an example of how it would work - from both sides

Frame 1 - the enemy will shoot if the player is in range.
Frame 2 - the enemy will only shoot if the player is in range and the player is overlapping a trigger object.

10. I followed the example for the one without the trigger, and it works on the pink enemies, but for some reason, it won't work on the black ones despite me doing the same thing.

Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•