I tried to write a ray tracing script, essentially, it's supposed to check if a particular event can see a particular map coordinate. Unfortunately, it doesn't seem to be working and I haven't a clue why, been trying to fix it for half an hour but I'm shooting in the dark here...
My code below:
class Game_Interpreter def get_event(i) if i == 0 return $game_map.events[@event_id] end if i > 0 return $game_map.events end end def sightBlocked(e, x, y) event = get_event(e) ex = event.x ey = event.y #get difference dx = x-ex dy = y-ey dist = Math.sqrt(dx*dx+dy*dy) #get ray increment amount incx = dx / dist incy = dy / dist #loop across ray and test if passable for i in 1..(dist) ex += incx ey += incy if !event.passable?(ex.floor, ey.floor, 0) #floor effectively returns the integer value of a float return true #sight blocked end end return false #sight not blocked endendNote: I am aware that the tracing may see past corners but that isn't the problem, it seems to be working only half the time, if that.
My code below:
class Game_Interpreter def get_event(i) if i == 0 return $game_map.events[@event_id] end if i > 0 return $game_map.events end end def sightBlocked(e, x, y) event = get_event(e) ex = event.x ey = event.y #get difference dx = x-ex dy = y-ey dist = Math.sqrt(dx*dx+dy*dy) #get ray increment amount incx = dx / dist incy = dy / dist #loop across ray and test if passable for i in 1..(dist) ex += incx ey += incy if !event.passable?(ex.floor, ey.floor, 0) #floor effectively returns the integer value of a float return true #sight blocked end end return false #sight not blocked endendNote: I am aware that the tracing may see past corners but that isn't the problem, it seems to be working only half the time, if that.