Skip to content

Commit 1f11a13

Browse files
three.js platformer: fix pushing into box sides, desync coin spin
Ground support now uses the full aabb footprint so it matches the 2d collision solver. Before, support was lost when the center crossed a platform edge while the aabbs still overlapped, so the solid collision gate flipped on in the already-overlapping state where the engine only applies a gentle push-away that player input could overpower. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
1 parent b351960 commit 1f11a13

1 file changed

Lines changed: 6 additions & 2 deletions

File tree

examples/threejs/platformer/game.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,9 +63,12 @@ class PlatformerObject extends LJS.ThreeJSObject
6363
continue; // top is above our feet, sides handled by 2d collision
6464
if (platform.height < groundHeight)
6565
continue; // already found something higher
66-
// check if this object is inside the platform footprint
66+
// check if this object's footprint overlaps the platform
67+
// use the full aabb so support matches the 2d collision solver,
68+
// otherwise the solid gate can flip on while already overlapping
6769
const delta = this.pos.subtract(platform.pos);
68-
if (Math.abs(delta.x) < platform.size.x/2 && Math.abs(delta.y) < platform.size.y/2)
70+
const sizeBoth = this.size.add(platform.size);
71+
if (Math.abs(delta.x) < sizeBoth.x/2 && Math.abs(delta.y) < sizeBoth.y/2)
6972
groundHeight = platform.height;
7073
}
7174
return groundHeight;
@@ -119,6 +122,7 @@ class Coin extends PlatformerObject
119122
super(pos, vec2(.6), group, zPos);
120123
this.angleVelocity = .03; // spin, the plugin syncs the mesh from angle
121124
this.angleDamping = 1; // do not slow down
125+
this.angle = pos.x + pos.y; // offset spin phase by position so coins are not in sync
122126
}
123127
update()
124128
{

0 commit comments

Comments
 (0)