fix: add random speed to fix: if enableCollisions are turned off and the marble completely overlaps, there will be no collision

This commit is contained in:
Usu171
2025-12-14 17:51:30 +08:00
parent 2f7630565d
commit d9f361280d
2 changed files with 8 additions and 0 deletions

View File

@@ -288,4 +288,11 @@ export class MarblePhysics {
ctx.fillText(`${speed.toFixed(0)}`, m.x + 5, m.y - 5);
}
}
public addRandomSpeed(marbles: Marble[]): void {
for (const m of marbles) {
m.vx += Math.random() * 2 - 1;
m.vy += Math.random() * 2 - 1;
}
}
}

View File

@@ -311,6 +311,7 @@ export class MarbleSystem {
// Toggle collision
public setCollisions(enabled: boolean): void {
this.physics.updateConfig({ enableCollisions: enabled });
this.physics.addRandomSpeed(this.marbles);
}
// Toggle debug mode (show velocity vectors)