From 4070aee9faa314c4b6f9d108c855c5e14b04c3d0 Mon Sep 17 00:00:00 2001 From: nico Date: Fri, 10 Jul 2026 20:07:01 +0200 Subject: [PATCH] Fix: precise ground/ceiling snap eliminates camera jitter MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Ground snap: scan for first solid below actor, place exactly on surface - Ceiling snap: scan for first solid above actor, place exactly beneath - Eliminates 1px gap that caused slow sink cycle → camera wobble fixed - Also fixes step-up early return preventing fall-through --- engine/src/actors.rs | 28 ++++++++++++++++++++-------- 1 file changed, 20 insertions(+), 8 deletions(-) diff --git a/engine/src/actors.rs b/engine/src/actors.rs index eca9a8d..bbe6144 100644 --- a/engine/src/actors.rs +++ b/engine/src/actors.rs @@ -88,17 +88,29 @@ impl Actor { if self.collides_at(grid, self.x, new_y) { if self.vy > 0.0 { - let mut sy = new_y; - while sy <= new_y + self.h as f32 && self.collides_at(grid, self.x, sy) { - sy -= 1.0; + let mut gy = (self.y + self.h as f32) as u32; + let max_y = (new_y + self.h as f32 + 2.0) as u32; + while gy <= max_y.min(grid.height) { + if grid.get(self.x.floor() as u32, gy) != 0 { + let props = &crate::material::PROPS[grid.get(self.x.floor() as u32, gy) as usize]; + if props.is_solid && !props.is_powder { + self.y = gy as f32 - self.h as f32; + break; + } + } + gy += 1; } - self.y = sy; } else { - let mut sy = new_y; - while sy >= new_y - self.h as f32 && self.collides_at(grid, self.x, sy) { - sy += 1.0; + let mut gy = (new_y - 2.0).max(0.0) as u32; + while gy > 0 { + let mat = grid.get(self.x.floor() as u32, gy); + let props = &crate::material::PROPS[mat as usize]; + if props.is_solid && !props.is_powder { + self.y = (gy + 1) as f32; + break; + } + gy -= 1; } - self.y = sy; } self.vy = 0.0; } else {