Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function line_of_sight(self, pos1, pos2, stepsize)
- stepsize = stepsize or 1
- local s, pos = minetest.line_of_sight(pos1, pos2, stepsize)
- -- normal walking and flying mobs can see you through air
- if s == true then
- return true
- end
- -- New pos1 to be analyzed
- local npos1 = {x = pos1.x, y = pos1.y, z = pos1.z}
- local r, pos = minetest.line_of_sight(npos1, pos2, stepsize)
- -- Checks the return
- if r == true then return true end
- -- Nodename found
- local nn = minetest.get_node(pos).name
- -- Target Distance (td) to travel
- local td = get_distance(pos1, pos2)
- -- Actual Distance (ad) traveled
- local ad = 0
- -- It continues to advance in the line of sight in search of a real obstruction.
- while minetest.registered_nodes[nn] and (minetest.registered_nodes[nn].walkable == false or nn == "default:snow") do
- -- Check if you can still move forward
- if td < ad + stepsize then
- return true -- Reached the target
- end
- -- Moves the analyzed pos
- local d = get_distance(pos1, pos2)
- npos1.x = ((pos2.x - pos1.x) / d * stepsize) + pos1.x
- npos1.y = ((pos2.y - pos1.y) / d * stepsize) + pos1.y
- npos1.z = ((pos2.z - pos1.z) / d * stepsize) + pos1.z
- ad = ad + stepsize
- -- scan again
- r, pos = minetest.line_of_sight(npos1, pos2, stepsize)
- if r == true then return true end
- -- New Nodename found
- nn = minetest.get_node(pos).name
- end
- return false
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement