Skip to content

Commit 297615f

Browse files
obiotclaude
andcommitted
Fix z-ordering reset during collision response
Vector3d.set(x, y) defaults z to 0, which wiped out the z position used for layer ordering when resolving collisions. Pass the existing z value explicitly to preserve draw order. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 9efa9fc commit 297615f

2 files changed

Lines changed: 3 additions & 0 deletions

File tree

packages/melonjs/src/physics/body.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -477,6 +477,7 @@ export default class Body {
477477
this.ancestor.pos.set(
478478
this.ancestor.pos.x - overlap.x * ratio,
479479
this.ancestor.pos.y - overlap.y * ratio,
480+
this.ancestor.pos.z,
480481
);
481482

482483
// cancel the velocity component along the collision normal

packages/melonjs/src/physics/detector.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,7 @@ class Detector {
195195
objA.body.ancestor.pos.set(
196196
objA.body.ancestor.pos.x - overlap.x * ratioA,
197197
objA.body.ancestor.pos.y - overlap.y * ratioA,
198+
objA.body.ancestor.pos.z,
198199
);
199200
// cancel velocity into this surface (no bounce)
200201
const projVel =
@@ -208,6 +209,7 @@ class Detector {
208209
objB.body.ancestor.pos.set(
209210
objB.body.ancestor.pos.x + overlap.x * ratioB,
210211
objB.body.ancestor.pos.y + overlap.y * ratioB,
212+
objB.body.ancestor.pos.z,
211213
);
212214
const projVel =
213215
objB.body.vel.x * overlapN.x + objB.body.vel.y * overlapN.y;

0 commit comments

Comments
 (0)