Parachute uses moveresult for collision detect
This commit is contained in:
parent
26b13a1583
commit
cfd5ab0875
@ -45,9 +45,8 @@ local function open_parachute_for_player(player, play_sound, load_area)
|
|||||||
|
|
||||||
if load_area then
|
if load_area then
|
||||||
-- Load area around parachute to make sure it doesn't spawn into ignore
|
-- Load area around parachute to make sure it doesn't spawn into ignore
|
||||||
local offset = vector.new(2,2,2)
|
local load1 = vector.add(ppos, vector.new(-2, -2, -2))
|
||||||
local load1 = vector.subtract(ppos, offset)
|
local load2 = vector.add(ppos, vector.new(2, 4, 2))
|
||||||
local load2 = vector.add(ppos, offset)
|
|
||||||
minetest.load_area(load1, load2)
|
minetest.load_area(load1, load2)
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -123,8 +122,15 @@ minetest.register_entity(
|
|||||||
visual = "mesh",
|
visual = "mesh",
|
||||||
mesh = "parachute.b3d",
|
mesh = "parachute.b3d",
|
||||||
textures = {"parachute_mesh.png"},
|
textures = {"parachute_mesh.png"},
|
||||||
physical = false,
|
|
||||||
pointable = false,
|
pointable = false,
|
||||||
|
physical = true,
|
||||||
|
collide_with_objects = true,
|
||||||
|
-- This collisionbox ranges from the feet of the player up to the top of the parachute.
|
||||||
|
-- That way, the parachute will collide when either the player feet touch the ground
|
||||||
|
-- or the parachute collides.
|
||||||
|
-- This collisionbox MUST be re-checked whenever the player model or collisionbox
|
||||||
|
-- was changed
|
||||||
|
collisionbox = {-0.5, -0.8, -0.5, 0.5, 2.8, 0.5},
|
||||||
automatic_face_movement_dir = -90,
|
automatic_face_movement_dir = -90,
|
||||||
static_save = false,
|
static_save = false,
|
||||||
|
|
||||||
@ -139,13 +145,37 @@ minetest.register_entity(
|
|||||||
local pos = self.object:get_pos()
|
local pos = self.object:get_pos()
|
||||||
self.start_y = pos.y
|
self.start_y = pos.y
|
||||||
end
|
end
|
||||||
|
self.object:set_acceleration({x=0,y=0,z=0})
|
||||||
end,
|
end,
|
||||||
on_step = function(self, dtime)
|
on_step = function(self, dtime, moveresult)
|
||||||
local pos = self.object:get_pos()
|
local is_ignore = false
|
||||||
local under = minetest.get_node({x = pos.x, y = pos.y - 1, z = pos.z})
|
local collides = false
|
||||||
if under.name ~= "ignore" then
|
-- Check for regular collision
|
||||||
|
if moveresult and moveresult.collides then
|
||||||
|
collides = true
|
||||||
|
local nodes = 0
|
||||||
|
for m=1, #moveresult.collisions do
|
||||||
|
local col = moveresult.collisions[m]
|
||||||
|
if col.type == "node" then
|
||||||
|
nodes = nodes + 1
|
||||||
|
end
|
||||||
|
end
|
||||||
|
if nodes == 0 then
|
||||||
|
is_ignore = true
|
||||||
|
end
|
||||||
|
end
|
||||||
|
if not collides then
|
||||||
|
-- Check for special collision in liquids and nodes that slow players (e.g. water, spikes)
|
||||||
|
local pos = self.object:get_pos()
|
||||||
|
local node = minetest.get_node(pos)
|
||||||
|
local def = minetest.registered_nodes[node.name]
|
||||||
|
if def and (def.liquidtype ~= "none" or def.liquid_move_physics == true or (def.move_resistance and def.move_resistance > 0)) then
|
||||||
|
collides = true
|
||||||
|
end
|
||||||
|
end
|
||||||
|
if not is_ignore then
|
||||||
self.ignore_mode = false
|
self.ignore_mode = false
|
||||||
end
|
end
|
||||||
|
|
||||||
if self.attached ~= nil then
|
if self.attached ~= nil then
|
||||||
local player = minetest.get_player_by_name(self.attached)
|
local player = minetest.get_player_by_name(self.attached)
|
||||||
@ -192,19 +222,21 @@ minetest.register_entity(
|
|||||||
|
|
||||||
accel.y = accel.y + air_physics(vel.y) * 0.25
|
accel.y = accel.y + air_physics(vel.y) * 0.25
|
||||||
|
|
||||||
if under.name ~= "ignore" then
|
if not is_ignore then
|
||||||
self.object:set_acceleration(accel)
|
self.object:set_acceleration(accel)
|
||||||
else
|
else
|
||||||
self.object:set_acceleration(vector.zero())
|
self.object:set_acceleration(vector.zero())
|
||||||
self.object:set_velocity(vector.zero())
|
self.object:set_velocity(vector.zero())
|
||||||
end
|
end
|
||||||
|
|
||||||
if under.name ~= "air" and (self.ignore_mode == false or under.name ~= "ignore") then
|
-- Destroy parachute if colliding
|
||||||
|
if collides and (self.ignore_mode == false or not is_ignore) then
|
||||||
rp_player.player_attached[self.attached] = false
|
rp_player.player_attached[self.attached] = false
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
if under.name ~= "air" and (self.ignore_mode == false or under.name ~= "ignore") then
|
-- Destroy parachute if colliding
|
||||||
|
if collides and (self.ignore_mode == false or not is_ignore) then
|
||||||
local player
|
local player
|
||||||
if self.attached ~= nil then
|
if self.attached ~= nil then
|
||||||
rp_player.player_attached[self.attached] = false
|
rp_player.player_attached[self.attached] = false
|
||||||
|
Loading…
x
Reference in New Issue
Block a user