mirror of
https://github.com/APercy/airutils.git
synced 2025-04-30 08:41:41 -04:00
improved vehicle attach
This commit is contained in:
parent
b51d1bdcae
commit
683a17ec18
1 changed files with 31 additions and 22 deletions
|
@ -20,23 +20,36 @@ local function attach_entity(self, target_obj, dest_pos, relative_pos, entity_na
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
function airutils.dettach_entity(self)
|
function airutils.get_attached_entity(self)
|
||||||
if not self._vehicle_custom_data then return end
|
if not self._vehicle_custom_data then return nil, nil end
|
||||||
if not self._vehicle_custom_data.simple_external_attach_entity then return end
|
if not self._vehicle_custom_data.simple_external_attach_entity then return nil, nil end
|
||||||
|
|
||||||
local entity_name = self._vehicle_custom_data.simple_external_attach_entity
|
local entity_name = self._vehicle_custom_data.simple_external_attach_entity
|
||||||
local relative_pos = self._vehicle_custom_data.simple_external_attach_pos
|
|
||||||
local inv_id = self._vehicle_custom_data.simple_external_attach_invid
|
local inv_id = self._vehicle_custom_data.simple_external_attach_invid
|
||||||
|
|
||||||
local pos = self.object:get_pos()
|
local pos = self.object:get_pos()
|
||||||
local velocity = self.object:get_velocity()
|
|
||||||
local nearby_objects = minetest.get_objects_inside_radius(pos, 32)
|
local nearby_objects = minetest.get_objects_inside_radius(pos, 32)
|
||||||
for i,obj in ipairs(nearby_objects) do
|
for i,obj in ipairs(nearby_objects) do
|
||||||
local ent = obj:get_luaentity()
|
local ent = obj:get_luaentity()
|
||||||
if ent then
|
if ent then
|
||||||
if ent._inv_id then
|
if ent._inv_id then
|
||||||
if ent._inv_id == inv_id then
|
if ent._inv_id == inv_id then
|
||||||
|
return ent, obj
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
return nil, nil
|
||||||
|
end
|
||||||
|
|
||||||
|
function airutils.dettach_entity(self)
|
||||||
|
local ent, obj = airutils.get_attached_entity(self)
|
||||||
|
if ent and obj then
|
||||||
|
local relative_pos = self._vehicle_custom_data.simple_external_attach_pos
|
||||||
|
local pos = self.object:get_pos()
|
||||||
local rotation = self.object:get_rotation()
|
local rotation = self.object:get_rotation()
|
||||||
local direction = rotation.y
|
local direction = rotation.y
|
||||||
|
local velocity = self.object:get_velocity()
|
||||||
|
|
||||||
local move = -1*relative_pos.z/10
|
local move = -1*relative_pos.z/10
|
||||||
pos.x = pos.x + move * math.sin(direction)
|
pos.x = pos.x + move * math.sin(direction)
|
||||||
|
@ -50,10 +63,6 @@ function airutils.dettach_entity(self)
|
||||||
self._vehicle_custom_data.simple_external_attach_entity = nil
|
self._vehicle_custom_data.simple_external_attach_entity = nil
|
||||||
self._vehicle_custom_data.simple_external_attach_pos = nil
|
self._vehicle_custom_data.simple_external_attach_pos = nil
|
||||||
self._vehicle_custom_data.simple_external_attach_invid = nil
|
self._vehicle_custom_data.simple_external_attach_invid = nil
|
||||||
break
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue