From 59f4865a0710032b1c102a17d9bce5e583ccbec0 Mon Sep 17 00:00:00 2001 From: Alexsandro Percy Date: Thu, 24 Aug 2023 20:14:00 -0300 Subject: [PATCH] improved vehicle destruction code --- lib_planes/custom_physics.lua | 1 + lib_planes/entities.lua | 5 +++++ physics_lib.lua | 2 ++ 3 files changed, 8 insertions(+) diff --git a/lib_planes/custom_physics.lua b/lib_planes/custom_physics.lua index 8e4a5f6..fba2bb3 100755 --- a/lib_planes/custom_physics.lua +++ b/lib_planes/custom_physics.lua @@ -7,6 +7,7 @@ function airutils.physics(self) local surface = nil local surfnodename = nil local spos = airutils.get_stand_pos(self) + if not spos then return end spos.y = spos.y+0.01 -- get surface height local snodepos = airutils.get_node_pos(spos) diff --git a/lib_planes/entities.lua b/lib_planes/entities.lua index ca49604..2119e81 100644 --- a/lib_planes/entities.lua +++ b/lib_planes/entities.lua @@ -119,6 +119,10 @@ function airutils.on_step(self,dtime,colinfo) end end + if self.hp_max <= 0 then + airutils.destroy(self) + end + self:physics() if self.logic then @@ -214,6 +218,7 @@ function airutils.logic(self) end end + if not self.object:get_acceleration() then return end local accel_y = self.object:get_acceleration().y local rotation = self.object:get_rotation() local yaw = rotation.y diff --git a/physics_lib.lua b/physics_lib.lua index d6702f5..3f58943 100755 --- a/physics_lib.lua +++ b/physics_lib.lua @@ -42,9 +42,11 @@ function airutils.get_stand_pos(thing) -- thing can be luaentity or objectref. local colbox = {} if type(thing) == 'table' then pos = thing.object:get_pos() + if not thing.object:get_properties() then return false end colbox = thing.object:get_properties().collisionbox elseif type(thing) == 'userdata' then pos = thing:get_pos() + if not thing:get_properties() then return false end colbox = thing:get_properties().collisionbox else return false