mirror of
https://github.com/ElCeejo/creatura.git
synced 2025-03-21 15:21:24 +00:00
Faster Line Of Sight
This commit is contained in:
parent
41dba26415
commit
a591c7c69c
1 changed files with 16 additions and 6 deletions
22
mob_meta.lua
22
mob_meta.lua
|
@ -33,11 +33,21 @@ local function vec_raise(v, n)
|
||||||
return {x = v.x, y = v.y + n, z = v.z}
|
return {x = v.x, y = v.y + n, z = v.z}
|
||||||
end
|
end
|
||||||
|
|
||||||
local function fast_ray_sight(pos1, pos2)
|
local function get_sightline(pos1, pos2)
|
||||||
local ray = minetest.raycast(pos1, pos2, false, false)
|
local dir = vec_dir(pos1, pos2)
|
||||||
for col in pairs(ray) do
|
local dist = vec_dist(pos1, pos2)
|
||||||
if col.type == "node"
|
for i = 0, dist do
|
||||||
and creatura.get_node_def(col.under).walkable then
|
local pos
|
||||||
|
if dist > 0 then
|
||||||
|
pos = {
|
||||||
|
x = pos1.x + dir.x * (i / dist),
|
||||||
|
y = pos1.y + dir.y * (i / dist),
|
||||||
|
z = pos1.z + dir.z * (i / dist)
|
||||||
|
}
|
||||||
|
else
|
||||||
|
pos = pos1
|
||||||
|
end
|
||||||
|
if creatura.get_node_def(pos).walkable then
|
||||||
return false
|
return false
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -632,7 +642,7 @@ function mob:get_target(target)
|
||||||
if not pos then return false, false, nil end
|
if not pos then return false, false, nil end
|
||||||
local tpos = target:get_pos()
|
local tpos = target:get_pos()
|
||||||
tpos.y = floor(tpos.y + 0.5)
|
tpos.y = floor(tpos.y + 0.5)
|
||||||
local line_of_sight = fast_ray_sight(pos, tpos)
|
local line_of_sight = get_sightline(pos, tpos)
|
||||||
return true, line_of_sight, tpos
|
return true, line_of_sight, tpos
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue