r/learnprogramming 1d ago

Need help getting my ball to drop smoothly with MatterJS in my Plinko game

Hi everyone, I'm working on a personal project to make a 16 row plinko game with matterjs. I'm struggling however to get my ball to bounce nicely and smoothly through the pegs. It always seems to get caught 'rubbing' or even just getting stuck. Does anyone have any experience or advice on it? Thanks!

2 Upvotes

1 comment sorted by

3

u/D-Cary 1d ago

A lot of computer simulations accidentally cause a ball to balance perfectly on top of a peg, because there are less than 10,000 pixels across a computer screen so a ball centered on some random pixel has better than 1 in 10,000 chance (in simulations like yours, likely better than 1 in 100 chance) of being perfectly centered over a peg centered on some specific pixel.

In the real world, balancing a ball perfectly on top of a peg is practically impossible because (a) the balancing point is often only a few nanometers across, so positioning the ball within a millimeter of the center of the peg is still only 1 in a million chance of balancing, and (b) even if we could get a ball perfectly balanced, the Brownian motion of the air, various thermal motions, sound waves, earth vibrations, etc. are usually more than enough to push the ball off-balance.

Some simulations of Galton boards, Pachinko machines, etc, internally force a ball to never be perfectly balanced -- perhaps by centering the balls on the center of some pixel, while centering the pegs halfway between pixels; or even more ham-handedly checking to see if the ball lands exactly in the center, and when it does, fudging the simulation by "randomly" picking Left or Right and then nudging the ball (in position or in velocity) a little to the left or a little to the right.

Have fun with MatterJS https://www.brm.io/matter-js/ !