cannon-es icon indicating copy to clipboard operation
cannon-es copied to clipboard

Unknown Force is applied on some vertically stacked cubes on straight plane?

Open prathamVaidya opened this issue 1 year ago • 4 comments

Check out the Video Proof

When three simple cubes are stacked together vertically, after some time the cube experience a force to the left direction. I checked the plane is not rotated at y or z axis. Am I missing something obvious or its just a bug in CannonJS?

prathamVaidya avatar Mar 06 '23 05:03 prathamVaidya

Yep this seems to be a known issue for cannon.. Even in the jenga example you'll notice that the blocks gradually move. (set solver iterations to 1 to speed this up). You can increase or decrease the time it takes by changing world solver iterations. However even at 50 iterations it still very slightly moves over time. The effect also seems to increase based on the gravity value.

I'd love to see a fix as this is a pretty prevalent issue

https://github.com/schteppe/cannon.js/issues/348 https://github.com/pmndrs/use-cannon/issues/240

johnnyrainbow avatar Jan 08 '24 17:01 johnnyrainbow

Is there an alternative solution to fix this unexpected behaviour?

I read about using sleep or downgrading versions. Did that really work?

@johnnyrainbow

prathamVaidya avatar Jan 09 '24 02:01 prathamVaidya

@prathamVaidya sleeping the body seems like the only realistic way to get around it.

Since you still want gravity to apply, what you could do is add a collision listener to the cube. When it collides with another cube, call cubeBody.sleep(). This will stop it from jittering. (Also make sure to use cubeBody.allowSleep = true when you initialise the body)

johnnyrainbow avatar Jan 09 '24 03:01 johnnyrainbow

One solution you could try is the "sleep" feature (see the sleep demo).

In my case, I had to set sleepTimeLimit to 0 and sleepSpeedLimit to 0.1. It worked perfectly.

gabrieldejesus avatar Jun 27 '24 21:06 gabrieldejesus