mirror of
https://github.com/101island/lolisland.us.git
synced 2026-03-01 03:49:42 +08:00
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:
@@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user