I was wondering if there was a way to trigger an event by facing it from any direction?
Trigger event by player looking at event?
RPG Maker VXAce SupportYes, there is. I generally prefer to do stuff like this with a bit of coding, but I'll stick to the event system this time around, no big deal. Keep in mind that this is a fairly advanced use of the event system. I would suggest you study the below example and try to figure out how to replicate it for all four directions.
Since we're working solely with the event system, this will require between 2 and 6 variables. In this example, I'll use 6 so that it's clear what it is I'm doing.
If you can figure out why that many isn't necessary, then by all means, use less of them. 🙂

The above example will only take effect if the player views the event from below. This doesn't take into account any obstructions between the player in the event. It also doesn't account for distance, but that's because I was bit lazy and wanted this to fit within one screenshot. 😀 The player and event X Y variables are set to the player's and event's map X values respectively. The threshold values are there to ensure that the event is within the player's field of vision on the map.
As for completing this event for all four directions, here's a hint:
If Player_Y is greater than Event_Y then the player is below the event on the map.
If Player_Y is less than Event_Y then the player is above the event on the map.
If Player_X is less than Event_X then the player is left of the event on the map.
If Player_X is greater than Event_X then the player is right of the event on the map.
Edit: Just in case, here's the completed event with distance taken into account.
Since we're working solely with the event system, this will require between 2 and 6 variables. In this example, I'll use 6 so that it's clear what it is I'm doing.
If you can figure out why that many isn't necessary, then by all means, use less of them. 🙂

The above example will only take effect if the player views the event from below. This doesn't take into account any obstructions between the player in the event. It also doesn't account for distance, but that's because I was bit lazy and wanted this to fit within one screenshot. 😀 The player and event X Y variables are set to the player's and event's map X values respectively. The threshold values are there to ensure that the event is within the player's field of vision on the map.
As for completing this event for all four directions, here's a hint:
If Player_Y is greater than Event_Y then the player is below the event on the map.
If Player_Y is less than Event_Y then the player is above the event on the map.
If Player_X is less than Event_X then the player is left of the event on the map.
If Player_X is greater than Event_X then the player is right of the event on the map.
Edit: Just in case, here's the completed event with distance taken into account.
Edit: Shoot, Rinobi / the others were faster by the time this comment gets approved or something.
Ahh well, not going to delete my comment. Only difference between mine and Rinobi's is that I used simply 4 variables instead of 6 and I did all 4 directions. ^^;
---
If you mean simply by literally looking at it, I do believe you just need to set the event's trigger to "Player Touch".
If you mean a bit more complicated way for cutscenes and such, I do believe you can do it by;
- Make an event that you want to trigger by facing it. ( I'm guessing it doesn't matter how distant you are from it as long as you're facing it? )
- Set it's priority to be parallel process, and;
> Set two variables down, for example, [player_x] and [player_y]. As the variable name suggests, each variables will get down the coordinates of the player.
( If you don't know how to do this, go to variable -> Game Data -> Character -> Player -> Map X, Map Y
> Do the same with the event, except this time you're going to set two different variables, for example, [event_x] and [event_y]. Do the same, except instead of "Player" when getting the coordinates, you will have "This event" chosen.
> Set up two conditional branches, one with the "if else" option, where you check if the Player's and Event's X are the same. If not, you check if the Player's Y and Event's Y are the same or not.
> If the X is the same, you have to now check whether the player's Y is bigger than the event's or not. If Y is bigger, you have to make yet another conditional branch if the player is facing up, and then you can proceed to write down what the event will do. If Y is smaller, then obviously you have to set the conditional branch to check if the player is facing down.
> Do the same with Y, except "up" switches with "left" and "down" switches with "right".
If you did everything right, the code should look like the attached file to this post.
I think you can figure out the rest. Hope this helped. 🙂

Ahh well, not going to delete my comment. Only difference between mine and Rinobi's is that I used simply 4 variables instead of 6 and I did all 4 directions. ^^;
---
If you mean simply by literally looking at it, I do believe you just need to set the event's trigger to "Player Touch".
If you mean a bit more complicated way for cutscenes and such, I do believe you can do it by;
- Make an event that you want to trigger by facing it. ( I'm guessing it doesn't matter how distant you are from it as long as you're facing it? )
- Set it's priority to be parallel process, and;
> Set two variables down, for example, [player_x] and [player_y]. As the variable name suggests, each variables will get down the coordinates of the player.
( If you don't know how to do this, go to variable -> Game Data -> Character -> Player -> Map X, Map Y
> Do the same with the event, except this time you're going to set two different variables, for example, [event_x] and [event_y]. Do the same, except instead of "Player" when getting the coordinates, you will have "This event" chosen.
> Set up two conditional branches, one with the "if else" option, where you check if the Player's and Event's X are the same. If not, you check if the Player's Y and Event's Y are the same or not.
> If the X is the same, you have to now check whether the player's Y is bigger than the event's or not. If Y is bigger, you have to make yet another conditional branch if the player is facing up, and then you can proceed to write down what the event will do. If Y is smaller, then obviously you have to set the conditional branch to check if the player is facing down.
> Do the same with Y, except "up" switches with "left" and "down" switches with "right".
If you did everything right, the code should look like the attached file to this post.
I think you can figure out the rest. Hope this helped. 🙂

Original thread: https://forums.rpgmakerweb.com/threads/trigger-event-by-player-looking-at-event.64381/



