Fix crashes with mobs below or above due division by zero

* removes a division by zero issue which returns nan for yaw
  in some places
master
mckaygerhard 2023-01-12 17:51:47 -04:00
parent 8bdf40b849
commit 95f3980694
2 changed files with 30 additions and 4 deletions

View File

@ -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

View File

@ -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