じ☆ve冰风 发表于 2026-8-1 13:33:33

[solved] Line of Sight - enemies have x-ray vision

Hello,


        I'm using Fomar0153's Line of Sight script.


        Currently I'm creating an area where the player has to sneak past patrolling enemies and use the environment to hide from them. However, I noticed that the enemies can actually see through walls. I would like the enemies to not see the player if there's a tile between them that cannot be passed.


        Does anyone know how to modify the script in such a way? I will post the script below - hope that is ok.

                Code:       
=begin
Line of Sight
by Fomar0153
Version 1.0
----------------------
Notes
----------------------
Allows you to have events trigger when they see the player
----------------------
Instructions
----------------------
Nametag events with:
<sight x>
where x is the range.

Also the events should be either player touch or event touch.
----------------------
Known bugs
----------------------
None
=end

class Game_Player < Game_Character
#--------------------------------------------------------------------------
# * Trigger Map Event
#   triggers : Trigger array
#   normal   : Is priority set to ?
#--------------------------------------------------------------------------
def start_sight_event(x, y, triggers, normal)
    return if $game_map.interpreter.running?
    $game_map.sight_xy(x, y).each do |event|
      if event.trigger_in?(triggers)
      event.start
      end
    end
end
#--------------------------------------------------------------------------
# * Determine if Same Position Event is Triggered
#--------------------------------------------------------------------------
alias sight_check_event_trigger_here check_event_trigger_here
def check_event_trigger_here(triggers)
    sight_check_event_trigger_here(triggers)
    start_sight_event(@x, @y, , true) if triggers.include?(1)
end
end

class Game_Map
#--------------------------------------------------------------------------
# * Get Array of Events at Designated Coordinates
#--------------------------------------------------------------------------
def sight_xy(x, y)
    @events.values.select {|event| event.see?(x, y) }
end
end

class Game_CharacterBase
#--------------------------------------------------------------------------
# * Determine Coordinate Match
#--------------------------------------------------------------------------
def see?(x, y)
    s = sight
    xx =
    yy =
    @x.between?(xx.min, xx.max) && @y.between?(yy.min, yy.max)
end
#--------------------------------------------------------------------------
# * Determine Range of Sight
#--------------------------------------------------------------------------
def sight
    if @sight.nil?
      if !@event.nil? && @event.name =~ /<sight (.*)>/i
      @sight = $1.to_i
      else
      @sight = 0
      end
    end
    @sight
end
end

class Game_Event < Game_Character
#--------------------------------------------------------------------------
# * Change Direction to Designated Direction
#   d : Direction (2,4,6,8)
#--------------------------------------------------------------------------
def set_direction(d)
    super
    check_player_spotted
end
#--------------------------------------------------------------------------
# * Determine if the player is in sight
#--------------------------------------------------------------------------
def check_player_spotted
    return if $game_map.interpreter.running? || @starting
    if @trigger == 2 && self.see?($game_player.x,$game_player.y)
      start if !jumping? && normal_priority?
    end
end
end




本贴来自国际rpgmaker官方论坛作者:Raen Andaleio处,因国际论坛即将永久关站,为了存档多年珍贵资料,署名转载到本论坛存档,由于官方帖子为英文原帖,需要中文翻译请点击论坛顶部切换语言为中文就可以将帖子翻译成中文浏览,方便大家随时查看,原文地址:https://forums.rpgmakerweb.com/threads/solved-line-of-sight-enemies-have-x-ray-vision.58904/
页: [1]
查看完整版本: [solved] Line of Sight - enemies have x-ray vision