After a few hours of googling and testing, i got this idea, and its a lot easier:
if the object is nearer then the position front of itso its just to check if the player is front of the mob

so you gets a viewfield that looks like this

Your phone or window isn't wide enough to display the code box. If it's a phone, try rotating it to landscape mode.
- Code: Select all
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