Fix: precise ground/ceiling snap eliminates camera jitter
- 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
This commit is contained in:
+20
-8
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user