I think you have to calculate that on your own. However, it is not a difficult task. In VX Ace, direction is as follows:
- DOWN -> 2;
- LEFT -> 4;
- RIGHT -> 6;
- UP -> 8.
To check if an event is to the left or to the right, you can subtract its horizontal coordinate to that of the player and compare it with player direction. The result is easily handled: if greater than 0, event is to the left, if less than 0, event is to the right. It works similarly for vertical coordinates.
That said, an easy way to get rid of multiple conditional branches is that of using
(5 - $game_player.direction) * x_coordinate_difference. In which case you just need to compare the result: if greater than 0, player is facing the other direction, if less than zero, player is facing the event.
In case of diagonal distance, you just have to compare the distance on each axis and pick the axis associated to the bigger one as your main axis to apply the previous formula.
So thanks for helping me out! I really appreciate you chiming in since it felt like I was stuck paddling in the middle of the ocean there.
👋
$game_player.direction is the answer I needed since I was trying to make an event through
Victor's Event Page Conditions where it tracks if the player is facing up towards the event, as it only takes valid ruby script calls.
The event in question is an eyeball that shoots at you if you look at it. It works like this:
Page 1 (shooting): $game_player.direction == 8, so if you're looking up at it, it fires
Page 2 (unaware): $game_player.direction < 8, so if you're looking in any other direction it doesn't fire
Page 3 (too far away): A distance variable I cooked up for another thread.
... However I'll admit I didn't fully grasp your
Ruby:
(5 - $game_player.direction) * x_coordinate_difference
example since x_coordinate_difference doesn't seem to work in there.
(This is in VX Ace Support because I just wanted a script call, not help with someone's script.)