collisionMoveSimple snaps a jumping object below the floor after a long step (5.17 regression)
Luanti version
5.17.0 (macOS, LuaJIT 2.1). The code path was introduced by fa956d13 ("Collision: Update position based on collisionbox faces"), which is in 5.17.0 and not in 5.16.1.
Operating system
macOS 26.6.2, arm64. This is server-side collision code, so CPU, GPU and renderer don't matter; the reproduction below uses a headless server.
Summary
A physical object just above a floor, with upward velocity and downward acceleration (a jumping mob, for example), is moved to below the floor when the next server step is longer than 2 * v.y / |a.y|. The engine places it with the top of its collision box against the floor node's underside, which buries it inside the terrain.
Minimal reproduction
A game with one mod, mg_name = singlenode, and a headless server:
-- A physical entity resting on a floor node jumps (v.y = 4.3, a.y = -14.71),
-- then the server stalls so the next step is long. Expected: the entity stays
-- at or above the floor top (y = 0.5). Observed in 5.17.0: y = -0.5 - 1.94 = -2.44.
core.register_node("repro:stone", {tiles = {"blank.png"}})
local STALL = tonumber(core.settings:get("repro_stall")) or 1.0
core.register_entity("repro:jumper", {
initial_properties = {
physical = true,
collisionbox = {-0.3, 0, -0.3, 0.3, 1.94, 0.3},
visual = "cube", textures = {"blank.png"},
},
on_activate = function(self)
self.object:set_acceleration({x = 0, y = -14.71, z = 0})
self.steps = 0
end,
on_step = function(self, dtime)
self.steps = self.steps + 1
local p = self.object:get_pos()
core.log("action", ("[repro] step %d dtime=%.3f y=%.3f vy=%.3f"):format(
self.steps, dtime, p.y, self.object:get_velocity().y))
if self.steps == 20 then
-- Jump from just above the floor (a mob mid-jump, or one whose
-- touching-ground gravity leaves a small gap), then make the next
-- step long.
self.object:set_pos({x = 0, y = 0.55, z = 0})
self.object:set_velocity({x = 0, y = 4.3, z = 0})
local t0 = core.get_us_time()
while core.get_us_time() - t0 < STALL * 1e6 do end
elseif self.steps == 25 then
core.request_shutdown()
end
end,
})
core.register_on_mods_loaded(function()
core.after(0, function()
core.emerge_area({x = -16, y = -16, z = -16}, {x = 15, y = 15, z = 15}, function(_, _, remaining)
if remaining > 0 then return end
core.forceload_block({x = 0, y = 0, z = 0}, true)
core.set_node({x = 0, y = 0, z = 0}, {name = "repro:stone"})
core.add_entity({x = 0, y = 0.5, z = 0}, "repro:jumper")
end)
end)
end)Output with repro_stall = 1.0 (the entity's box bottom starts 0.05 above the floor top at 0.5):
[repro] step 20 dtime=0.095 y=0.500 vy=0.000
[repro] step 21 dtime=1.000 y=-2.440 vy=0.000
[repro] step 22 dtime=0.092 y=-2.502 vy=-1.347-2.440 is exactly the floor node's bottom (-0.5) minus the box height (1.94). The threshold matches the analysis below (2 * 4.3 / 14.71 = 0.58 s): repro_stall = 0.5 leaves the entity above the floor, and repro_stall = 0.7 buries it.
Cause
In collisionMoveSimple, the nearest collision is found using aspeed_f averaged over the whole remaining dtime. For a long enough step, gravity makes that average negative, so the floor below is found as a Y collision with nearest_dtime > 0. Before resolving it, the loop recomputes aspeed_f for the sub-interval up to contact:
aspeed_f = *speed_f + accel_f * 0.5f * nearest_dtime;That value is still positive. collide_with<&v3f::Y> then chooses the face from the sign of this recomputed speed:
pos_f->*AX = speed < 0.0f
? (box_stat.MaxEdge.*AX - box_mov.MinEdge.*AX)
: (box_stat.MinEdge.*AX - box_mov.MaxEdge.*AX);So the floor is treated as a ceiling, and the object ends up at floor.MinEdge.Y - box.MaxEdge.Y. Before fa956d13, the position was advanced by velocity and was never snapped to a face, so the mismatched sign was harmless.
Impact
VoxeLibre mobs jump with v.y = 4.3 and have gravity of -14.71, so any server step longer than about 0.6 s can bury a mob that is starting a jump. The mob then suffocates. In singleplayer, a client hitch is enough to cause a step that long. With a forced 2.3 s stall every 20 s in an established village, several villagers were buried at every stall. Downstream report and workaround: https://github.com/tbook/luanti-villages/issues/90
Expected
The object stays on the floor, as it does in 5.16.
Possible fix
Choose the face in collide_with from the sign of the speed that detected the collision (the aspeed_f that axisAlignedCollision was given), rather than from the recomputed sub-interval speed. Alternatively, choose it from which side of the static box the moving box started on.
Source: luanti-org/luanti