Someone that know how to calculate / or know where to find code, to check if an object is in field of view?
I think it could be something to sneak behind mobs without to be detected.
VanessaE in IRC wrote:there's a line-of-sight call or two in the API I think
https://github.com/minetest/minetest/blob/master/doc/lua_api.txt#L2323
AiTechEye wrote:Someone that know how to calculate / or know where to find code, to check if an object is in field of view?
I think it could be something to sneak behind mobs without to be detected.
function is_front_of(pos1,pos2)
local pos1=self.object:getpos()
local pos2=ob:getpos()
local l1=distance(pos1,pos2)
local l2=distance(aliveai.pointat(self,1),pos2)
return l1>l2
end
function distance(pos1,pos2)
return math.sqrt((pos1.x-pos2.x)*(pos1.x-pos2.x) + (pos1.y-pos2.y)*(pos1.y-pos2.y)+(pos1.z-pos2.z)*(pos1.z-pos2.z))
end
function pointat(self,d)-- get position front of object
local pos=self.object:getpos()
local yaw=self.object:getyaw()
d=d or 1
local x =math.sin(yaw) * -d
local z =math.cos(yaw) * d
return {x=pos.x+x,y=pos.y,z=pos.z+z}
end
Users browsing this forum: No registered users and 53 guests