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.collides_at(grid, self.x, new_y) {
|
||||||
if self.vy > 0.0 {
|
if self.vy > 0.0 {
|
||||||
let mut sy = new_y;
|
let mut gy = (self.y + self.h as f32) as u32;
|
||||||
while sy <= new_y + self.h as f32 && self.collides_at(grid, self.x, sy) {
|
let max_y = (new_y + self.h as f32 + 2.0) as u32;
|
||||||
sy -= 1.0;
|
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 {
|
} else {
|
||||||
let mut sy = new_y;
|
let mut gy = (new_y - 2.0).max(0.0) as u32;
|
||||||
while sy >= new_y - self.h as f32 && self.collides_at(grid, self.x, sy) {
|
while gy > 0 {
|
||||||
sy += 1.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;
|
self.vy = 0.0;
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
Reference in New Issue
Block a user