fix: Improve rabbit collision, rotation, and jumping mechanics
This commit is contained in:
@@ -76,12 +76,22 @@ class Entity {
|
||||
const halfWidth = this.width / 2;
|
||||
const halfHeight = this.height / 2;
|
||||
|
||||
// Check bottom points for ground collision
|
||||
const bottomLeft = { x: newX - halfWidth * 0.8, y: newY + halfHeight };
|
||||
const bottomRight = { x: newX + halfWidth * 0.8, y: newY + halfHeight };
|
||||
// Check bottom points for ground collision - check multiple points along the bottom
|
||||
const numBottomPoints = 5;
|
||||
let groundCollision = false;
|
||||
|
||||
if (this.isPixelSolid(bottomLeft.x, bottomLeft.y) ||
|
||||
this.isPixelSolid(bottomRight.x, bottomRight.y)) {
|
||||
for (let i = 0; i < numBottomPoints; i++) {
|
||||
const ratio = i / (numBottomPoints - 1);
|
||||
const bottomX = newX - halfWidth + (2 * halfWidth * ratio);
|
||||
const bottomY = newY + halfHeight;
|
||||
|
||||
if (this.isPixelSolid(bottomX, bottomY)) {
|
||||
groundCollision = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (groundCollision) {
|
||||
result.collision = true;
|
||||
result.vertical = true;
|
||||
result.ground = true;
|
||||
@@ -112,7 +122,8 @@ class Entity {
|
||||
}
|
||||
|
||||
isPixelSolid(x, y) {
|
||||
const pixel = getPixel(Math.floor(x), Math.floor(y));
|
||||
// Use ceiling for y coordinate to better detect ground below
|
||||
const pixel = getPixel(Math.floor(x), Math.ceil(y));
|
||||
return pixel !== EMPTY &&
|
||||
pixel !== WATER &&
|
||||
pixel !== FIRE &&
|
||||
|
||||
Reference in New Issue
Block a user