I am currently developing a Plinko game using Matter.js. I’ve written code to ensure that the result is always determined by the ball’s initial position, without any external influence.
For example, in the test environment, when I drop the ball from x: 100, y: 0, it always lands in the same spot. However, during actual gameplay, the results are inconsistent and differ from the test results.
dropBall(path: number[] = [], start: number, test: boolean = false) {
const { friction, frictionAirByRowCount } = PlinkoEngine.ballFrictions;
// const startX = this.canvas.width / 2;
const startX = start
const startY = 0;
const ballRadius = this.pinRadius * 2;
const ball = Bodies.circle(startX, startY, ballRadius, {
label: 'ball',
restitution: 0.9,
friction,
frictionAir: frictionAirByRowCount[this.rowCount],
collisionFilter: {
category: PlinkoEngine.BALL_CATEGORY,
mask: PlinkoEngine.PIN_CATEGORY,
},
render: { fillStyle: '#ff0000' },
path: path,
start: start,
test: test
});
Composite.add(this.engine.world, ball);
this.gameStore.updateBetAmountOfExistingBalls(ball.id, this.betAmount);
this.gameStore.updateBalance(-this.betAmount);
}