Check if player is facing a moving event

Hello!
I wonder if there's a way to check if the player is facing a moving event?

I want the event to trigger only if the player is facing the event.

I have it set up so that it's triggering in a radius around the event (parallell process) and a conditional branch checking if the player clicks mouse button to shoot. But I don't want the event(enemy) to take damage if the player isn't facing the event.

Any way to make this check in another conditional branch?


--
I'm using MV3D and YEP_EventProxActivate to make it 3D and to make it check the player's distance compared to the events.

Only need a conditional branch to check if player is facing the event now 🙂
Hope to get some help! Thanks in advance!
I believe there are plugins that can do this... eventing such a system from scratch is possible, but quite tedious.

You'd need to check for multiple scenarios, depending on the event's position in relation to the player's combined with the direction the player is facing.
I believe there are plugins that can do this... eventing such a system from scratch is possible, but quite tedious.

You'd need to check for multiple scenarios, depending on the event's position in relation to the player's combined with the direction the player is facing.
Do you know of such a plugin?
Eventing it will be fine too, tedious isn't a problem 🙂
I don't know a specific plugin unfortunately, but google should lead you to one.

If you know how to use script calls, you can get it done with just 4 conditional branches to check for these 4 scenarios (P = player, E = event):

PX = EX & PY < EY & P facing up
PX = EX & PY > EY & P facing down
PY = EY & PX < EX & P facing right
PY = EY & PX > EX & P facing left

Without script calls, I wouldn't bother tbh.. because you'd need to assign unique variables for the X and Y coordinates of each event, which is extremely tedious and ineffecient (unless we're talking about a small number of events).
I don't know a specific plugin unfortunately, but google should lead you to one.

If you know how to use script calls, you can get it done with just 4 conditional branches to check for these 4 scenarios (P = player, E = event):

PX = EX & PY < EY & P facing up
PX = EX & PY > EY & P facing down
PY = EY & PX < EX & P facing right
PY = EY & PX > EX & P facing left

Without script calls, I wouldn't bother tbh.. because you'd need to assign unique variables for the X and Y coordinates of each event, which is extremely tedious and ineffecient (unless we're talking about a small number of events).
I'll see if I can get that working.. Not a big scripter myself.
Yeah, I have googled all day without any result. maybe just unlucky.

Have an examplye how the actual script call would look like if I go with that direction?
The script for the first scenario should be something like this:

$gamePlayer.x == $gameMap.event(this.eventId()).x && $gamePlayer.y < $gameMap.event(this.eventId()).y && $gamePlayer.direction() == 8

And then the rest are pretty much just following the same pattern. You can consult the script call list here in the forums for the exact functions.

Good luck 😀
The script for the first scenario should be something like this:

$gamePlayer.x == $gameMap.event(this.eventId()).x && $gamePlayer.y < $gameMap.event(this.eventId()).y && $gamePlayer.direction() == 8

And then the rest are pretty much just following the same pattern. You can consult the script call list here in the forums for the exact functions.

Good luck 😀
Thanks I'll get it and see if I can make the miracle come true ❤️

EDIT:
These are the scripts I put into the 4 conditional branches:
Code:
$gamePlayer.x == $gameMap.event(this.eventId()).x && $gamePlayer.y < $gameMap.event(this.eventId()).y && $gamePlayer.direction() == 8
Code:
$gamePlayer.x == $gameMap.event(this.eventId()).x && $gamePlayer.y > $gameMap.event(this.eventId()).y && $gamePlayer.direction() == 2
Code:
$gamePlayer.y == $gameMap.event(this.eventId()).y && $gamePlayer.x < $gameMap.event(this.eventId()).x && $gamePlayer.direction() == 6
Code:
$gamePlayer.y == $gameMap.event(this.eventId()).y && $gamePlayer.x > $gameMap.event(this.eventId()).x && $gamePlayer.direction() == 4

And this is how the event looks. It seeeeem to work.
Did I understand it correctly or am I overthinking it? xD
not sure maybe if the player is facing up down right left and get the position(x,y) of the target/enemy,
its somewhere there.. this will require a lot maybe
Tip: It's sometimes easier to create a (small) plugin like this:

Code:
Game_Event.prototype.isFacedByPlayer = function() {
    return ($gamePlayer.direction() == 2 && $gamePlayer.y < this.y)
        || ($gamePlayer.direction() == 4 && $gamePlayer.x > this.x)
        || ($gamePlayer.direction() == 6 && $gamePlayer.x < this.x)
        || ($gamePlayer.direction() == 8 && $gamePlayer.y > this.y);
}

Then in your IF Condition, you can shortcut to $gameMap.event(this.eventId()).isFacedByPlayer()
Thanks for the tip, will try both and see what works best
Code:
Game_Event.prototype.isFacedByPlayer = function() {
return ($gamePlayer.direction() == 2 && $gamePlayer.y < this.y)
|| ($gamePlayer.direction() == 4 && $gamePlayer.x > this.x)
|| ($gamePlayer.direction() == 6 && $gamePlayer.x < this.x)
|| ($gamePlayer.direction() == 8 && $gamePlayer.y > this.y);
}
Then in your IF Condition, you can shortcut to $gameMap.event(this.eventId()).isFacedByPlayer()
I tried it and it seems to works as good as the other longe one.
Big thanks! Will be really helpful for the rest of the game!
The script for the first scenario should be something like this:

$gamePlayer.x == $gameMap.event(this.eventId()).x && $gamePlayer.y < $gameMap.event(this.eventId()).y && $gamePlayer.direction() == 8

And then the rest are pretty much just following the same pattern. You can consult the script call list here in the forums for the exact functions.

Good luck 😀
You will both be added to the Credits of the game <3
---
(Admin: I didn't find how to edit the other post and make a reply into that so sorry for doubleposting)

Original thread: https://forums.rpgmakerweb.com/threads/check-if-player-is-facing-a-moving-event.160509/