设为首页收藏本站同能贴吧 切换语言 繁体中文
开启辅助访问 切换到窄版
扫描二维码关注官方公众号
返回列表
+ 发新帖
查看: 116|回复: 0

[转载发布] [solved] Line of Sight - enemies have x-ray vision

[复制链接]
累计送礼:
0 个
累计收礼:
1 个
  • TA的每日心情
    开心
    2026-7-12 04:10
  • 签到天数: 209 天

    连续签到: 2 天

    [LV.7]常住居民III

    9071

    主题

    864

    回帖

    6万

    积分

    管理员

    Rank: 9Rank: 9Rank: 9

    VIP
    7
    卡币
    58883
    OK点
    16
    推广点
    0
    同能卷
    50
    积分
    68848

    灌水之王

    发表于 2026-8-1 13:33:33 | 显示全部楼层 |阅读模式
    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:       
    1. =begin
    2. Line of Sight
    3. by Fomar0153
    4. Version 1.0
    5. ----------------------
    6. Notes
    7. ----------------------
    8. Allows you to have events trigger when they see the player
    9. ----------------------
    10. Instructions
    11. ----------------------
    12. Nametag events with:
    13. <sight x>
    14. where x is the range.
    15. Also the events should be either player touch or event touch.
    16. ----------------------
    17. Known bugs
    18. ----------------------
    19. None
    20. =end
    21. class Game_Player < Game_Character
    22.   #--------------------------------------------------------------------------
    23.   # * Trigger Map Event
    24.   #     triggers : Trigger array
    25.   #     normal   : Is priority set to [Same as Characters] ?
    26.   #--------------------------------------------------------------------------
    27.   def start_sight_event(x, y, triggers, normal)
    28.     return if $game_map.interpreter.running?
    29.     $game_map.sight_xy(x, y).each do |event|
    30.       if event.trigger_in?(triggers)
    31.         event.start
    32.       end
    33.     end
    34.   end
    35.   #--------------------------------------------------------------------------
    36.   # * Determine if Same Position Event is Triggered
    37.   #--------------------------------------------------------------------------
    38.   alias sight_check_event_trigger_here check_event_trigger_here
    39.   def check_event_trigger_here(triggers)
    40.     sight_check_event_trigger_here(triggers)
    41.     start_sight_event(@x, @y, [1,2], true) if triggers.include?(1)
    42.   end
    43. end
    44. class Game_Map
    45.   #--------------------------------------------------------------------------
    46.   # * Get Array of Events at Designated Coordinates
    47.   #--------------------------------------------------------------------------
    48.   def sight_xy(x, y)
    49.     @events.values.select {|event| event.see?(x, y) }
    50.   end
    51. end
    52. class Game_CharacterBase
    53.   #--------------------------------------------------------------------------
    54.   # * Determine Coordinate Match
    55.   #--------------------------------------------------------------------------
    56.   def see?(x, y)
    57.     s = sight
    58.     xx = [x, x - (@direction == 6 ? 1 : @direction == 4 ? -1 : 0) * s]
    59.     yy = [y, y - (@direction == 2 ? 1 : @direction == 8 ? -1 : 0) * s]
    60.     @x.between?(xx.min, xx.max) && @y.between?(yy.min, yy.max)
    61.   end
    62.   #--------------------------------------------------------------------------
    63.   # * Determine Range of Sight
    64.   #--------------------------------------------------------------------------
    65.   def sight
    66.     if @sight.nil?
    67.       if !@event.nil? && @event.name =~ /<sight (.*)>/i
    68.         @sight = $1.to_i
    69.       else
    70.         @sight = 0
    71.       end
    72.     end
    73.     @sight
    74.   end
    75. end
    76. class Game_Event < Game_Character
    77.   #--------------------------------------------------------------------------
    78.   # * Change Direction to Designated Direction
    79.   #     d : Direction (2,4,6,8)
    80.   #--------------------------------------------------------------------------
    81.   def set_direction(d)
    82.     super
    83.     check_player_spotted
    84.   end
    85.   #--------------------------------------------------------------------------
    86.   # * Determine if the player is in sight
    87.   #--------------------------------------------------------------------------
    88.   def check_player_spotted
    89.     return if $game_map.interpreter.running? || @starting
    90.     if @trigger == 2 && self.see?($game_player.x,$game_player.y)
    91.       start if !jumping? && normal_priority?
    92.     end
    93.   end
    94. end
    复制代码




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

    使用道具 举报

    文明发言,和谐互动
    文明发言,和谐互动
    高级模式
    您需要登录后才可以回帖 登录 | 立即注册

    本版积分规则

    简体中文
    繁體中文
    English(英语)
    日本語(日语)
    Deutsch(德语)
    Русский язык(俄语)
    بالعربية(阿拉伯语)
    Türkçe(土耳其语)
    Português(葡萄牙语)
    ภาษาไทย(泰国语)
    한어(朝鲜语/韩语)
    Français(法语)
    关闭

    幸运抽奖

    社区每日抽奖来袭,快来试试你是欧皇还是非酋~

    立即查看

    聊天机器人
    Loading...

    QQ|Archiver|手机版|小黑屋|同能RPG制作大师 ( 沪ICP备12027754号-3 )

    GMT+8, 2026-8-17 23:19 , Processed in 0.133984 second(s), 52 queries .

    Powered by Discuz! X3.4

    Copyright © 2001-2020, Tencent Cloud.

    快速回复 返回顶部 返回列表