1
0
Fork 0

Add some mob object checks to avoid crashing

This commit is contained in:
ancientmarinerdev 2023-01-16 16:27:11 +00:00 committed by Gitea
parent 9a276489d1
commit 2cd6629ae1
1 changed files with 16 additions and 10 deletions

View File

@ -186,10 +186,12 @@ function mob_class:slow_mob()
local d = 0.85 local d = 0.85
if self:check_dying() then d = 0.92 end if self:check_dying() then d = 0.92 end
local v = self.object:get_velocity() if self.object then
if v then local v = self.object:get_velocity()
--diffuse object velocity if v then
self.object:set_velocity({x = v.x*d, y = v.y, z = v.z*d}) --diffuse object velocity
self.object:set_velocity({x = v.x*d, y = v.y, z = v.z*d})
end
end end
end end
@ -518,9 +520,11 @@ function mob_class:check_for_death(cause, cmi_cause)
}) })
self:set_velocity(0) self:set_velocity(0)
local acc = self.object:get_acceleration() if self.object then
acc.x, acc.y, acc.z = 0, DEFAULT_FALL_SPEED, 0 local acc = self.object:get_acceleration()
self.object:set_acceleration(acc) acc.x, acc.y, acc.z = 0, DEFAULT_FALL_SPEED, 0
self.object:set_acceleration(acc)
end
local length local length
-- default death function and die animation (if defined) -- default death function and die animation (if defined)
@ -980,9 +984,11 @@ end
function mob_class:check_dying() function mob_class:check_dying()
if ((self.state and self.state=="die") or self:check_for_death()) and not self.animation.die_end then if ((self.state and self.state=="die") or self:check_for_death()) and not self.animation.die_end then
local rot = self.object:get_rotation() if self.object then
rot.z = ((math.pi/2-rot.z)*.2)+rot.z local rot = self.object:get_rotation()
self.object:set_rotation(rot) rot.z = ((math.pi/2-rot.z)*.2)+rot.z
self.object:set_rotation(rot)
end
return true return true
end end
end end