How to check if player interacts from behind?

Hi everyone! I´ve been trying to make a game. I learned a lot since I started last week, but now I am having serious trouble.

I want to implement a stealth section. I managed to make a simple event thanks to the incredible Proximity Sensor Plugin from reflector88 (https://reflector88.itch.io/proximity-sensor), in wich if you are in the line of sight of that event, it will trigger a switch.

While that implementation is super usefull, I still need to implement a "takedown", requiring to interact with the moving event from behind. This last part, I am unable to find a solution for. I´ve been checking pages and sites for hours on end, witouth any success.

So if anyone would happen to know how to program an event that not only moves and checks if you are in its line of vision, but also is capable of being killed, taken down, deactivated, whatever you name it, I would be more than grateful. I will attach a screenshot of the coding of the event I managed to get going, if anyone would need to see.

Thanks for reading! Have a nice day.
You could just check if both the player and event are facing the same direction
Use Control Variables to store the player's direction, a second one to store the event's direction, Conditional Branch to see if they're the same.
You could just check if both the player and event are facing the same direction
Hello! I tried that, but as the event trigger is in "paralell", anytime I even spawned in the map (so I would by default look down), it would trigger the "erase event" path before I can even move...

Use Control Variables to store the player's direction, a second one to store the event's direction, Conditional Branch to see if they're the same.
Hi, thanks for the answer! That seems a little complex to me, so I will be trying to implement it and watch a tutorial to complement the process. I will return and post if I managed to do it.
By default events "lock" to face the player when activated. To get around this, there are various options:
  • Use Direction Fix on the event (awkward to turn on/off if movement involves turns);
  • Use a script call to get the pre-lock direction of This Event (this.character(0)._prelockDirection);
  • Look for a helpful plugin, e.g. one that lets you decide when events are allowed to "lock".

If the event has to be triggered by the player, then like others have said, you can just check if they're facing the same way, e.g.

◆Comment:Check difference in directions. ◆Control Variables:#0001 Check = this.character(0)._prelockDirection ◆Control Variables:#0001 Check -= Direction of Player ◆If:Check = 0 ◆Comment:Success!
However, if the event can trigger the interaction then you will also need a coordinate check, to ensure the player is behind the event rather than vice versa. E.g.
Spoiler: event example
◆Comment:Track success with self-switch. ◆Control Self Switch:A = OFF ◆Comment:Check difference in directions. ◆Control Variables:#0006 Target X = this.character(0)._prelockDirection ◆Control Variables:#0006 Target X -= Direction of Player ◆If:Target X = 0 ◆Comment:Both facing same direction, so now check difference in position. ◆Control Variables:#0006 Target X = Map X of Player ◆Control Variables:#0007 Target Y = Map Y of Player ◆Comment:Offset to target, based on direction. ◆If:Player is facing Down ◆Control Variables:#0007 Target Y += 1 ◆ :Else ◆If:Player is facing Left ◆Control Variables:#0006 Target X -= 1 ◆ :Else ◆If:Player is facing Right ◆Control Variables:#0006 Target X += 1 ◆ :Else ◆Control Variables:#0007 Target Y -= 1 ◆ :End ◆ :End ◆ :End ◆Comment:Compare against actual target location. ◆Control Variables:#0006 Target X -= Map X of This Event ◆If:Target X = 0 ◆Control Variables:#0007 Target Y -= Map Y of This Event ◆If:Target Y = 0 ◆Comment:Stealth successful! ◆Control Self Switch:A = ON ◆ :End ◆ :End ◆ :End ◆Comment:Now respond~ ◆If:Self Switch A is ON ◆Text:None, None, Window, Bottom : :OUCH! ◆ :Else ◆Text:None, None, Window, Bottom : :Oi, what do you think you're doing? ◆ :End
Use Control Variables to store the player's direction, a second one to store the event's direction, Conditional Branch to see if they're the same.
I almost dropped the towel, but in the end managed to get what you were saying! My grattitude is vast, thank you very much!

For anyone in the future that may search something similar, here is the simplest explanation I can give.

You will need 3 events, the enemy itself, and 2 events that perpetually copy the X and Y coordinates of both the player, and the enemy itself.


By looping the events that copy the coordinates, they will be constantly refreshing their X and Y coordinates.

The event that copy the enemy coords will need to get a "wait" time, so whenever it moves, he will leave the location of its previous tile, as a kind of trail. That trail will be the window of action player will get to trigger an "from behind" event.


The only problem is that the enemy needs to be constantly moving to leave said trail, and you may need to adjust the "wait" in the enemy coords event, to adjust to the walking speed, or leave more or less of a window.

Anyways, that is enough for my needs. A million thanks, Turan. This wouldn´t have been possible without your help.
By default events "lock" to face the player when activated. To get around this, there are various options:
  • Use Direction Fix on the event (awkward to turn on/off if movement involves turns);
  • Use a script call to get the pre-lock direction of This Event (this.character(0)._prelockDirection);
  • Look for a helpful plugin, e.g. one that lets you decide when events are allowed to "lock".

If the event has to be triggered by the player, then like others have said, you can just check if they're facing the same way, e.g.

◆Comment:Check difference in directions.
◆Control Variables:#0001 Check = this.character(0)._prelockDirection
◆Control Variables:#0001 Check -= Direction of Player
◆If:Check = 0
◆Comment:Success!

However, if the event can trigger the interaction then you will also need a coordinate check, to ensure the player is behind the event rather than vice versa. E.g.
Spoiler: event example
◆Comment:Track success with self-switch.
◆Control Self Switch:A = OFF

◆Comment:Check difference in directions.
◆Control Variables:#0006 Target X = this.character(0)._prelockDirection
◆Control Variables:#0006 Target X -= Direction of Player
◆If:Target X = 0

◆Comment:Both facing same direction, so now check difference in position.
◆Control Variables:#0006 Target X = Map X of Player
◆Control Variables:#0007 Target Y = Map Y of Player

◆Comment:Offset to target, based on direction.
◆If:Player is facing Down
◆Control Variables:#0007 Target Y += 1
◆
:Else
◆If:Player is facing Left
◆Control Variables:#0006 Target X -= 1
◆
:Else
◆If:Player is facing Right
◆Control Variables:#0006 Target X += 1
◆
:Else
◆Control Variables:#0007 Target Y -= 1
◆
:End
◆
:End
◆
:End

◆Comment:Compare against actual target location.
◆Control Variables:#0006 Target X -= Map X of This Event
◆If:Target X = 0
◆Control Variables:#0007 Target Y -= Map Y of This Event
◆If:Target Y = 0
◆Comment:Stealth successful!
◆Control Self Switch:A = ON
◆
:End
◆
:End
◆
:End

◆Comment:Now respond~
◆If:Self Switch A is ON
◆Text:None, None, Window, Bottom
: :OUCH!
◆
:Else
◆Text:None, None, Window, Bottom
: :Oi, what do you think you're doing?
◆
:End
I already found a solution, sorry for arriving late... Either way, its a phenomenal explication, so Imma try to implement it anyways. Thank you very much for your time!
You will need 3 events, the enemy itself, and 2 events that perpetually copy the X and Y coordinates of both the player, and the enemy itself.
Why do you need so many events? One event can record the coordinates of the player and anything else you want.

Also, Parallel and Autorun events already run continuously:
1710628796165.png


You don't want to put a Loop command inside of that.

Original thread: https://forums.rpgmakerweb.com/threads/how-to-check-if-player-interacts-from-behind.166877/