diff --git a/mods/mobs/api.lua b/mods/mobs/api.lua index 81d87a7..818b079 100644 --- a/mods/mobs/api.lua +++ b/mods/mobs/api.lua @@ -638,7 +638,14 @@ end function mobs:face_pos(self,pos) local s = self.object:getpos() local vec = {x=pos.x-s.x, y=pos.y-s.y, z=pos.z-s.z} - local yaw = math.atan(vec.z/vec.x)+math.pi/2 + local yaw = 0 + if vec.x ~= 0 then + yaw=math.atan(vec.z/vec.x)+math.pi/2 + else + if vec.z>0 then + yaw=math.pi + end + end if self.drawtype == "side" then yaw = yaw+(math.pi/2) end diff --git a/mods/mobs/step.lua b/mods/mobs/step.lua index 04433af..626c488 100644 --- a/mods/mobs/step.lua +++ b/mods/mobs/step.lua @@ -144,7 +144,14 @@ function mobs.on_step(self,dtime) end local vec = {x=p.x-s.x, y=p.y-s.y, z=p.z-s.z} - local yaw = math.atan(vec.z/vec.x)+math.pi/2 + local yaw = 0 + if vec.x ~= 0 then + yaw=math.atan(vec.z/vec.x)+math.pi/2 + else + if vec.z>0 then + yaw=math.pi + end + end if self.drawtype == "side" then yaw = yaw+(math.pi/2) end @@ -223,7 +230,13 @@ function mobs.on_step(self,dtime) end local vec = {x=p.x-s.x, y=p.y-s.y, z=p.z-s.z} - local yaw = math.atan(vec.z/vec.x)+math.pi/2 + if vec.x ~= 0 then + yaw=math.atan(vec.z/vec.x)+math.pi/2 + else + if vec.z>0 then + yaw=math.pi + end + end if self.drawtype == "side" then yaw = yaw+(math.pi/2) end @@ -345,7 +358,13 @@ function mobs.on_step(self,dtime) self.v_start = false else local vec = {x=p.x-s.x, y=p.y-s.y, z=p.z-s.z} - local yaw = math.atan(vec.z/vec.x)+math.pi/2 + if vec.x ~= 0 then + yaw=math.atan(vec.z/vec.x)+math.pi/2 + else + if vec.z>0 then + yaw=math.pi + end + end if self.drawtype == "side" then yaw = yaw+(math.pi/2) end