Awesome, thanks a lot, I'll do a loop iterating through all positions from the enemy to the hero using test_obstacle!
Here's a mockup:
function line_of_sight(entity)
local hasLOS = true
local heroDistance = entity:get_distance(hero)
local heroAngle = entity:get_angle(hero)
for i=0, heroDistance do
local dx, dy = math.cos(heroAngle)*i, -math.sin(heroAngle)*i
if entity:test_obstacles(dx, dy) then
hasLOS = false
break
end
end
return hasLOS
end
Edit It works, thank you so much!!! Also had to invert the Y for some reason, I guess Lua does its math in Cartesian coordinates (negative y towards the bottom)...
Included is the final script for anyone interested.