Skip to content

Commit e8e5d28

Browse files
committedMay 6, 2020
Enable collide_with_objects for falling entities
falling nodes intentionally still fall through players fixes #5313
1 parent 723926a commit e8e5d28

File tree

1 file changed

+21
-2
lines changed

1 file changed

+21
-2
lines changed
 

Diff for: ‎builtin/game/falling.lua

+21-2
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ core.register_entity(":__builtin:falling_node", {
4343
textures = {},
4444
physical = true,
4545
is_visible = false,
46-
collide_with_objects = false,
46+
collide_with_objects = true,
4747
collisionbox = {-0.5, -0.5, -0.5, 0.5, 0.5, 0.5},
4848
},
4949

@@ -272,9 +272,14 @@ core.register_entity(":__builtin:falling_node", {
272272
end
273273

274274
local bcp, bcn
275+
local player_collision
275276
if moveresult.touching_ground then
276277
for _, info in ipairs(moveresult.collisions) do
277-
if info.axis == "y" then
278+
if info.type == "object" then
279+
if info.axis == "y" and info.object:is_player() then
280+
player_collision = info
281+
end
282+
elseif info.axis == "y" then
278283
bcp = info.node_pos
279284
bcn = core.get_node(bcp)
280285
break
@@ -284,6 +289,20 @@ core.register_entity(":__builtin:falling_node", {
284289

285290
if not bcp then
286291
-- We're colliding with something, but not the ground. Irrelevant to us.
292+
if player_collision then
293+
-- Continue falling through players by moving a little into
294+
-- their collision box
295+
-- TODO: this hack could be avoided in the future if objects
296+
-- could choose who to collide with
297+
local vel = self.object:get_velocity()
298+
self.object:set_velocity({
299+
x = vel.x,
300+
y = player_collision.old_velocity.y,
301+
z = vel.z
302+
})
303+
self.object:set_pos(vector.add(self.object:get_pos(),
304+
{x = 0, y = -0.2, z = 0}))
305+
end
287306
return
288307
elseif bcn.name == "ignore" then
289308
-- Delete on contact with ignore at world edges

0 commit comments

Comments
 (0)
Please sign in to comment.