public

Rpg Maker Developers Group

Simple enough for a child, powerful enough for a developer

2 Followers

Line of Sight problems

BMM Archive · July 16, 2026

Preserved forum archive. This topic stores the original first post and locally mirrored RPG Maker Web attachments when available. It is posted by the BMMPlay archive account, not by the original creator.

Original Source

  • Original title: Line of Sight problems
  • Original author: JoePro
  • Original date: July 31, 2014
  • Source thread: https://forums.rpgmakerweb.com/threads/line-of-sight-problems.30579/
  • Source forum path: Game Development Engines > Ruby Game System (RGSS) Scripts > Learning Ruby and RGSSx

Summary

Hello all, I'm currently (was) working on a script to determine an events line of sight.   The event sees the player, regaurdless of obstructions, as long as it is facing the player. This should not be the case unless the obstruction is marked with a region id to make it become transparent to the event.

Archived First Post

Hello all,
I'm currently (was) working on a script to determine an events line of sight.
 
The event sees the player, regaurdless of obstructions, as long as it is facing the player. This should not be the case unless the obstruction is marked with a region id to make it become transparent to the event.
 
Here is the script and a link to the demo so you can see an example of the issue.


Script

 #################################################################################↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓##↓                                                                            ↓##↓                     Xpanded Event Control: Version 0.3                     ↓##↓                                                                            ↓##↕↕↕↕↕↕↕↕↕↕↕↕↕↕↕↕↕↕↕↕↕↕↕↕↕↕↕↕↕↕↕↕↕↕↕↕↕↕↕↕↕↕↕↕↕↕↕↕↕↕↕↕↕↕↕↕↕↕↕↕↕↕↕↕↕↕↕↕↕↕↕↕↕↕↕↕↕↕##↑                                                                            ↑##↑                          Written By: Joe Pro                            ↑##↑                        Last Edited: August 3, 2014                         ↑##↑                                                                            ↑##↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑##################################################################################◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙##◙ ** Disclaimer                                                              ◙##◙••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••◙##◙                                                                            ◙##◙ This script is not for commercial, if you wish to use this script in a     ◙##◙ game please PM me at which ever site you found this script. Either way,    ◙##◙ give me credit as the writer of this script.                               ◙##◙                                                                            ◙##◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙##◙ ** How To Use                                                              ◙##◙••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••◙##◙                                                                            ◙##◙ * Use the example below in an event script call to refer to the current    ◙##◙   event. Works like a self ( or the method get_charactor(0) )for scripting ◙##◙   within an event.                                                         ◙##◙                                                                            ◙##◙    event_self                                                              ◙##◙                                                                            ◙##◙ * Use the example below in an event script call to find the proximity of   ◙##◙   the current event to the player.                                         ◙##◙                                                                            ◙##◙    proximity?                                                              ◙##◙                                                                            ◙##◙ * Use the example below in an event script call to find if the current     ◙##◙   event can see the player.                                                ◙##◙                                                                            ◙##◙    viewable?                                                               ◙##◙                                                                            ◙##◙ * Use the example below in an event script call to find the direction of   ◙##◙   the player from the event.                                               ◙##◙                                                                            ◙##◙    player_direction                                                        ◙##◙                                                                            ◙##◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙##◙ ** Updates / Version Notes                                                 ◙##◙••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••◙##◙                                                                            ◙##◙   v0.1                                                                     ◙##◙ ~◄◙◙◙◙►~                                                                   ◙##◙ * This script adds more checks and methods for interactions between the    ◙##◙   game player and events. It currently allows for proximity checks and     ◙##◙   and a line of sight system.                                              ◙##◙                                                                            ◙##◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙##################################################################################↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓##↓                                                                            ↓##↓                      Keep EXP Save Spots: Version 0.1                      ↓##↑                                                                            ↑##↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑##################################################################################==============================================================================# ** Xpanded Event Control Module#------------------------------------------------------------------------------#  This module manages the customizable and function modules.#==============================================================================module Xpanded_Event_Control  #◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙##◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙##◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙Customizeable Area◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙##◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙##◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙#  #=============================================================================  # * Line of Sight Options  #=============================================================================    Transparent_Region_ID = 1    Default_Distance = 8 #◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙##◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙##◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙End Customizeable Area◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙##◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙##◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙#end#==============================================================================# ** Game_Character#------------------------------------------------------------------------------#  A character class with mainly movement route and other such processing# added. It is used as a super class of Game_Player, Game_Follower,# GameVehicle, and Game_Event.#==============================================================================class Game_Character < Game_CharacterBase  #--------------------------------------------------------------------------  # * Public Instance Variables  #--------------------------------------------------------------------------  attr_accessor  :wait_time               # forced move route flag  #--------------------------------------------------------------------------  # * Aliasing_method: Initialize Public Member Variables  #--------------------------------------------------------------------------  alias :gcipv32104506450 :init_public_members      #--------------------------------------------------------------------------  # * Initialize Public Member Variables  #--------------------------------------------------------------------------  def init_public_members    gcipv32104506450()    @wait_time = 0  end end#==============================================================================# ** Game_Event#------------------------------------------------------------------------------#  This class handles events. Functions include event page switching via# condition determinants and running parallel process events. Used within the# Game_Map class.#==============================================================================class Game_Event < Game_Character  #--------------------------------------------------------------------------  # * Aliasing_method: Move Type : Random  #--------------------------------------------------------------------------  alias :gemtr0401000004564 :move_type_random      #--------------------------------------------------------------------------  # * Move Type : Random  #--------------------------------------------------------------------------  def move_type_random    if self.wait_time > 0      self.wait_time -= 1    else      gemtr0401000004564()      self.wait_time = (rand(240) + 60) if rand(6) == 1    end  end   #--------------------------------------------------------------------------  # * Move Type : Approach  #--------------------------------------------------------------------------  def move_type_toward_player    if near_the_player?      move_toward_player    else      move_random    end  end   #--------------------------------------------------------------------------  # * Determine if Player is Within Proximity  #--------------------------------------------------------------------------  def proximity_to_player?    return (x_proximity_to_player? + y_proximity_to_player?)  end   #--------------------------------------------------------------------------  # * Determine if Player is Within X Proximity  #--------------------------------------------------------------------------  def x_proximity_to_player?    return (self.x > $game_player.x) ? self.x - $game_player.x : $game_player.x - self.x  end   #--------------------------------------------------------------------------  # * Determine if Player is Within Y Proximity  #--------------------------------------------------------------------------  def y_proximity_to_player?    return (self.y > $game_player.y) ? self.y - $game_player.y : $game_player.y - self.y  end   #--------------------------------------------------------------------------  # * Returns the Direction of the Player From This Event  #--------------------------------------------------------------------------  def oppisite_direction    case @direction    when 2      return 8    when 4      return 6    when 6      return 4    when 8      return 2    end  end   #--------------------------------------------------------------------------  # * Returns the Direction of the Player From This Event  #--------------------------------------------------------------------------  def player_direction    return (x_proximity_to_player? > y_proximity_to_player? ? (self.x > $game_player.x ? 4 : 6) : (self.y > $game_player.y ? 8 : 2))  end   #------------------------------------------------------------------------  # * Return All Comments  #------------------------------------------------------------------------  def return_all_comments    comments = []    @list.each { |command| comments.push command.parameters[0] if command.code == 108 } if @list    return comments  end    #--------------------------------------------------------------------------  # * Distance Viewable  #--------------------------------------------------------------------------  def distance    comments = return_all_comments    comments.each { |comment|      comment.scan(/distance:\s*(\d*)/im)      return $1.to_i if $1    }    return Xpanded_Event_Control:efault_Distance  end   #--------------------------------------------------------------------------  # * Determine if Player is Within Line of Sight.  #--------------------------------------------------------------------------  def line_of_sight?    return (player_direction != oppisite_direction)  end   #--------------------------------------------------------------------------  # * Determine if Player is Within View Without Obstruction  #--------------------------------------------------------------------------  def viewable?    viewable = true    ex = self.x    ey = self.y    px = $game_player.x    py = $game_player.y  #---------------------------------------------------------#  # * Checking if the Player is in the Events Line of Sight #  #---------------------------------------------------------#    if line_of_sight?  #------------------------------------------#  # * Checking if Within Proximity of Player #  #------------------------------------------#      if distance > proximity_to_player?  #---------------------------------#  # * Checking for any Obstructions #  #---------------------------------#        y_proximity_to_player?.times { |y|          x_proximity_to_player?.times { |x|            case            when (ex < px)              if (ey < py)                viewable = false if !$game_map.passable?((ex + x), (ey + y), @direction)              else                viewable = false if !$game_map.passable?((ex + x), (ey - y), @direction)              end            when (ex > px)              if (ey < py)                viewable = false if !$game_map.passable?((ex - x), (ey + y), @direction)              else                viewable = false if !$game_map.passable?((ex - x), (ey - y), @direction)              end            end          }        }  #----------------------------------------------------------------#  # * Checking for any Obstructions if y_proximity_to_player? == 0 #  #----------------------------------------------------------------#        x_proximity_to_player?.times { |x|          case          when (ex < px)            viewable = false if !$game_map.passable?((ex + x), ey, @direction)          when (ex > px)            viewable = false if !$game_map.passable?((ex - x), ey, @direction)          end          } if y_proximity_to_player? == 0  #----------------------------------------------------------------#  # * Checking for any Obstructions if x_proximity_to_player? == 0 #  #----------------------------------------------------------------#        y_proximity_to_player?.times { |y|          case          when (ey < py)            viewable = false if !$game_map.passable?(ex, (ey - y), @direction)          when (ey > py)            viewable = false if !$game_map.passable?(ex, (ey + y), @direction)          end          } if x_proximity_to_player? == 0  #---------------------------------------------------#  # * Returns false if distance < proximity_to_player?#  #---------------------------------------------------#      else        viewable = false      end  #------------------------------------#  # * Returns false if !line_of_sight? #  #------------------------------------#    else      viewable = false    end    return viewable  end end#==============================================================================# ** Game_Interpreter#------------------------------------------------------------------------------#  An interpreter for executing event commands. This class is used within the# Game_Map, Game_Troop, and Game_Event classes.#==============================================================================class Game_Interpreter  #--------------------------------------------------------------------------  # * Get the Proximity of Event to Player  #--------------------------------------------------------------------------  def proximity?    get_character(0).proximity_to_player?  end  #--------------------------------------------------------------------------  # * Get the Direction of the Player From This Event  #--------------------------------------------------------------------------  def player_direction    get_character(0).player_direction  end  #--------------------------------------------------------------------------  # * Get the Direction of the Player From This Event  #--------------------------------------------------------------------------  def viewable?    get_character(0).viewable?  end  #--------------------------------------------------------------------------  # * Returns Current Event  #--------------------------------------------------------------------------  def event_self    get_character(0)  endend
 
 
Demo
http://www.mediafire.com/download/u3g52k94452voq4/Xpanded_Events_Demo.zip
 
*****Edit*****​
 ​
This is a very fast mock up with a screenshot of my problem.
 
The red squares with X's represent a solid wall. The blue empty squares represent an obstruction that can still be seen through. Basically the rest of the script seems to be working fine, as far as I can tell. My only problem is if I am standing directly in front of the event, it will always see me, even if the path is obstructed.

 
 
Photos

Protected download
 
*****Edit*****​
 ​
I have set up the viewable? method to now print to the console the current event to player cases. I noticed that it is not printing any of the == conditioned cases.
 
I've fixed the problem above but the event still has a question mark even though it is returning false. Is there something wrong with the event.


here are the images incase you don't want to download the demo.
 

Protected download
Protected download
Protected download
Protected download
Protected download
***FIXED.

Mod can close this post, Thank you all!

Downloads / Referenced Files

Log in to download

Log in, then follow the RPG Maker Developers Group to see these download links.

Log in to download

License / Terms Note

 #################################################################################↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓##↓                                                                            ↓##↓                     Xpanded Event Control: Version 0.3                     ↓##↓                                                                            ↓##↕↕↕↕↕↕↕↕↕↕↕↕↕↕↕↕↕↕↕↕↕↕↕↕↕↕↕↕↕↕↕↕↕↕↕↕↕↕↕↕↕↕↕↕↕↕↕↕↕↕↕↕↕↕↕↕↕↕↕↕↕↕↕↕↕↕↕↕↕↕↕↕↕↕↕↕↕↕##↑                                                                            ↑##↑                          Written By: Joe Pro                            ↑##↑                        Last Edited: August 3, 2014                         ↑##↑                                                                            ↑##↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑##################################################################################◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙##◙ ** Disclaimer                                                              ◙##◙••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••◙##◙                                                                            ◙##◙ This script is not for commercial, if you wish to use this script in a     ◙##◙ game please PM me at which ever site you found this script. Either way,    ◙##◙ give me credit as the writer of this script.                               ◙##◙                                                                            ◙##◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙◙##◙ ** How To Use                                                              ◙##◙••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••◙##◙                                                                            ◙##◙ * Use the example below...

Referenced Images / Attachments

Line of Sight.png
Line of Sight.png
1.png
1.png
2.png
2.png
3.png
3.png
4.png
4.png
5.png
5.png
Creator Claims / Removal

If you are the original creator and want this listing reassigned, edited, or removed, join BMMPlay and contact the moderators with proof that matches the original RPG Maker Web profile, linked GitHub, itch.io page, or another public creator identity.

#039#end#rpg-maker-archive#rgss-learning

Replies (0)

No replies yet.

0 replies 1 view

Log in to reply.

User Avatar