Working immovable physics
This commit is contained in:
@@ -84,17 +84,38 @@ fn resolve_aabb_collisions(mut query: Query<(&mut PhysicsBody2D, &AABBCollider)>
|
|||||||
let dy = b.pos.y - other_b.pos.y;
|
let dy = b.pos.y - other_b.pos.y;
|
||||||
|
|
||||||
if other_b.immovable {
|
if other_b.immovable {
|
||||||
let new_x = match dx {
|
// move backwards along dx/dy until we're out
|
||||||
..0 => other_b.pos.x - (c.width / 2 + other_c.width / 2) as i64,
|
|
||||||
0 => b.pos.x,
|
let (new_x, new_y) = match dx.abs() > dy.abs() {
|
||||||
1.. => other_b.pos.x + (c.width / 2 + other_c.width / 2) as i64,
|
true => {
|
||||||
};
|
let dist = (c.width + other_c.width) as i64 / 2;
|
||||||
let new_y = match dy {
|
|
||||||
..0 => other_b.pos.y - (c.height / 2 + other_c.height / 2) as i64,
|
match dx > 0 {
|
||||||
0 => b.pos.y,
|
true => (other_b.pos.x + dist, b.pos.y),
|
||||||
1.. => other_b.pos.y + (c.height / 2 + other_c.height / 2) as i64,
|
false => (other_b.pos.x - dist, b.pos.y),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
false => {
|
||||||
|
let dist = (c.height + other_c.height) as i64 / 2;
|
||||||
|
|
||||||
|
match dy > 0 {
|
||||||
|
true => (b.pos.x, other_b.pos.y + dist),
|
||||||
|
false => (b.pos.x, other_b.pos.y - dist),
|
||||||
|
}
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// let new_x = match dx {
|
||||||
|
// ..0 => other_b.pos.x - (c.width / 2 + other_c.width / 2) as i64,
|
||||||
|
// 0 => b.pos.x,
|
||||||
|
// 1.. => other_b.pos.x + (c.width / 2 + other_c.width / 2) as i64,
|
||||||
|
// };
|
||||||
|
// let new_y = match dy {
|
||||||
|
// ..0 => other_b.pos.y - (c.height / 2 + other_c.height / 2) as i64,
|
||||||
|
// 0 => b.pos.y,
|
||||||
|
// 1.. => other_b.pos.y + (c.height / 2 + other_c.height / 2) as i64,
|
||||||
|
// };
|
||||||
|
|
||||||
let updated_b = PhysicsBody2D {
|
let updated_b = PhysicsBody2D {
|
||||||
pos: I64Vec2 { x: new_x, y: new_y },
|
pos: I64Vec2 { x: new_x, y: new_y },
|
||||||
vel: b.vel,
|
vel: b.vel,
|
||||||
|
|||||||
Reference in New Issue
Block a user