fix: rejected collision movement

This commit is contained in:
cha0s 2024-11-11 23:00:33 -06:00
parent aaa78c99c5
commit 6b3136a0b5

View File

@ -105,35 +105,30 @@ export default class Collider extends Component {
const otherAabb = other.aabbs[oj];
const {Position} = thisEntity;
const {lastX, lastY} = Position;
if (!intersects(
const {x, y} = Position;
if (intersects(
{
x0: aabb.x0 + Position.lastX,
x1: aabb.x1 + Position.lastX,
y0: aabb.y0 + Position.y,
y1: aabb.y1 + Position.y,
},
otherAabb,
)) {
Position.x = lastX;
Position.lastX = lastX;
}
else if (!intersects(
{
x0: aabb.x0 + Position.x,
x1: aabb.x1 + Position.x,
y0: aabb.y0 + Position.lastY,
y1: aabb.y1 + Position.lastY,
x0: aabb.x0 + lastX,
x1: aabb.x1 + lastX,
y0: aabb.y0 + y,
y1: aabb.y1 + y,
},
otherAabb,
)) {
Position.y = lastY;
Position.lastY = lastY;
}
else {
if (intersects(
{
x0: aabb.x0 + x,
x1: aabb.x1 + x,
y0: aabb.y0 + lastY,
y1: aabb.y1 + lastY,
},
otherAabb,
)) {
Position.x = lastX;
Position.lastX = lastX;
Position.y = lastY;
Position.lastY = lastY;
}
break;
}