mirror of
https://github.com/APercy/ap_airship.git
synced 2025-03-15 07:51:20 +00:00
first collision experiments
This commit is contained in:
parent
6b03e50dbe
commit
a78f1069b3
3 changed files with 91 additions and 0 deletions
47
entities.lua
47
entities.lua
|
@ -321,6 +321,47 @@ minetest.register_entity('ap_airship:chair_interactor',{
|
|||
on_rightclick = right_click_chair,
|
||||
})
|
||||
|
||||
minetest.register_entity('ap_airship:ent_collider',{
|
||||
initial_properties = {
|
||||
physical = true,
|
||||
collide_with_objects=true,
|
||||
collisionbox = {-2, 0, -2, 2, 3, 2},
|
||||
visual = "mesh",
|
||||
mesh = "ap_airship_stand_base.b3d",
|
||||
textures = {"ap_airship_alpha.png",},
|
||||
pointable=false,
|
||||
},
|
||||
dist_moved = 0,
|
||||
max_hp = 65535,
|
||||
|
||||
on_activate = function(self,std)
|
||||
self.sdata = minetest.deserialize(std) or {}
|
||||
if self.sdata.remove then self.object:remove() end
|
||||
end,
|
||||
|
||||
get_staticdata=function(self)
|
||||
self.sdata.remove=true
|
||||
return minetest.serialize(self.sdata)
|
||||
end,
|
||||
|
||||
on_punch = function(self, puncher, ttime, toolcaps, dir, damage)
|
||||
--minetest.chat_send_all("punch")
|
||||
if not puncher or not puncher:is_player() then
|
||||
return
|
||||
end
|
||||
end,
|
||||
|
||||
on_step = function(self,dtime,colinfo)
|
||||
self.dtime = math.min(dtime,0.2)
|
||||
self.colinfo = colinfo
|
||||
|
||||
if colinfo then
|
||||
self.isonground = colinfo.touching_ground
|
||||
--inetest.chat_send_all("touching ground: "..self.isonground)
|
||||
end
|
||||
end,
|
||||
})
|
||||
|
||||
--
|
||||
-- seat pivot
|
||||
--
|
||||
|
@ -458,6 +499,12 @@ minetest.register_entity("ap_airship:airship", {
|
|||
ap_airship.paint2(self, self.color2)
|
||||
local pos = self.object:get_pos()
|
||||
|
||||
--cabin collider
|
||||
self._cabin=minetest.add_entity(pos,'ap_airship:ent_collider')
|
||||
self._cabin:set_attach(self.object,'',{x=0,y=-28,z=118},{x=0,y=0,z=0})
|
||||
self._cabin2=minetest.add_entity(pos,'ap_airship:ent_collider')
|
||||
self._cabin2:set_attach(self.object,'',{x=0,y=-28,z=158},{x=0,y=0,z=0})
|
||||
|
||||
--passengers positions
|
||||
self._passenger_is_sit = ap_airship.copy_vector({})
|
||||
self._passengers_base = ap_airship.copy_vector({})
|
||||
|
|
|
@ -0,0 +1,42 @@
|
|||
|
||||
|
||||
function ap_airship.eval_interception(initial_pos, end_pos)
|
||||
local cast = minetest.raycast(initial_pos, end_pos, true, false)
|
||||
local thing = cast:next()
|
||||
while thing do
|
||||
if thing.type == "node" then
|
||||
local pos = thing.intersection_point
|
||||
if pos then
|
||||
local nodename = minetest.get_node(thing.under).name
|
||||
local drawtype = get_nodedef_field(nodename, "drawtype")
|
||||
if drawtype ~= "plantlike" then
|
||||
return true
|
||||
end
|
||||
end
|
||||
end
|
||||
thing = cast:next()
|
||||
end
|
||||
return false
|
||||
end
|
||||
|
||||
local function get_target_distance(pos, target)
|
||||
local x1, y1 = pos.x, pos.z
|
||||
local x2, y2 = target.x, target.z
|
||||
local distance = math.sqrt((x2 - x1)^2 + (y2 - y1)^2)
|
||||
|
||||
return distance
|
||||
end
|
||||
|
||||
--retorna uma posição de outra derivando de distancia e direção
|
||||
local function shift_target_by_direction(origin, direction, distance)
|
||||
local shifted_target = {x=0,y=origin.y,z=0}
|
||||
direction = direction / 360
|
||||
direction = ((direction - math.floor(direction))*360)
|
||||
local direction_rad = math.rad(direction)
|
||||
shifted_target = {x=math.cos(direction_rad)*distance,y=origin.y,z=math.sin(direction_rad)*distance}
|
||||
shifted_target.x = origin.x + shifted_target.x
|
||||
shifted_target.z = origin.z + shifted_target.z
|
||||
--airship_ap.print_l("origin x: "..origin.x.." - z: "..origin.z.." - target x: "..shifted_target.x.." - z: "..shifted_target.z.." - yaw: "..direction.." - target distance: "..distance)
|
||||
return shifted_target
|
||||
end
|
||||
|
|
@ -301,6 +301,8 @@ function ap_airship.destroy(self, overload)
|
|||
|
||||
if self._cabin_interactor then self._cabin_interactor:remove() end
|
||||
if self._control_interactor then self._control_interactor:remove() end
|
||||
if self._cabin then self._cabin:remove() end
|
||||
if self._cabin2 then self._cabin2:remove() end
|
||||
|
||||
airutils.destroy_inventory(self)
|
||||
self.object:remove()
|
||||
|
|
Loading…
Add table
Reference in a new issue