Direction Based Line of Sight
I made this mostly for touch encounter games to help add a little personality to the touch encounters. I also think that this can be utilized for puzzles and stealth missions in games.
This tutorial was made with the default scripts. There may be incompatibility with some scripts, particularly pixel movement scripts in which case you would have to completely rewrite the Conditional Branch script calls using the syntax of those scripts. Another that comes to mind would be an 8 directional movement script in which case you may need to take the concepts presented here and expand them to include the additional directions.
You can download the project file here. I recommend you play through the test game to get a feel of the events before you read the tutorial.
Glossary of Terms used in Script Calls
*Note: I am not a scripter and have a limited understanding of RGSS3, so if I got any of the descriptions wrong, I will not be offended if you correct me in the comment section below.
$game_map.events[@event_id] – this is used to get information about the currently running event @event_id is the same as saying this event if you need a specific event on a map just use it’s event id number which is displayed in the upper left hand corner when you edit the event.
$game_player – this used to get information about the player
(compared values).abs – is used to get the absolute value between them. Absolute values are always positive.
$game_map.events[@event_id].x – this gets the X coordinate value of the currently running event’s position on the map
$game_map.events[@event_id].y – this gets the Y coordinate value of the currently running event’s position on the map
$game_player.x – this gets the X coordinate value of the player’s position on the map
$game_player.y – this gets the Y coordinate value of the player’s position on the map
$game_map.events[@event_id].direction – this gets the value of which direction the currently running event is currently facing.
$game_player.direction – this gets the value of which direction the player is currently facing
- Direction Key:
- 2 is down
- 8 is up
- 4 is left
- 6 is right
&& – when used between to conditions basically means “and”. If there are multiple && used then all conditions must be met.
|| – when used, is basically a line break and can be said to be the same as “or”. If this is used in a conditional branch script call that means any of the conditions will be enough to satisfy the conditional branch.
The X/ Y Coordinate Plane and Relative Values
In mathematics the X axis is horizontal and the Y axis is vertical and is generally written as (x,y). This is true in RPG Maker as well and you can see this in the bottom right hand corner of the map editor. In RPG Maker coordinate (0,0) is in the upper left hand corner which means as you go right from (0,0) the X value increases and as you go down from (0,0) the Y value increases.
A relative value compares two objects on a coordinate plane and finds the difference between them. This tutorial utilizes this and also uses script calls that use less than and greater than X and/ or Y comparisons to determine where an object is relative to a different object.
I’ll use the above image to illustrate some examples:
- the X value of the spider is less than the X value of Ralph
- the X value of the scorpion is greater than the X value of Ralph
- the Y value of the bat is less than the Y value of Ralph
- the Y value of the hornet is greater than the Y value of Ralph