Help needed with physics engine (Cannon) behavior

I don’t have a good PG sample to show the problem but here is a YT video - Cannon engine issue - YouTube
The problem is that the bricks on the bridge starts to slowly slowly move around without a force being applied - as opposed to the bricks on the ground. Perhaps this is a rounding issue? Any ideas would be more that appreciated.

This is really hard to tell :frowning: maybe @RaananW would know when he ll be back from his break.

The only thing I could think of would be a lack of friction but totally not sure.

Thanks. Friction doesn’t help though. More background, the bricks, both on the ground and on the bridge, have Y gravity pushing them down, no other force. I have solved the issue for now using the “oncollide” event when a brick collides with the bridge, resetting the angular and the linear velocity to 0 if they are beneath a small threshold (0.1).

I’d say make sure the bridge is set to static and that it and all the dominos are set to be in sleep state intially.

The bridge has mass 0 (which makes it static right?) and can’t do sleep since the dominoes are supposed to fall when eventually knocked over.

They should awake if interacted with though I think.

Im pretty sure sleep is a temporary state, but should settle the collision noise on the intial placement.

I’m not sure if you have to manually wake them up or not.

Maybe @Cedric has some ideas?

It looks like small precision issues adding over time.

I guess the bridge is using triangle mesh, can you try with a compound of box instead? To make it easy to test, create only 1 box for the bridge. I think precision issue will disappear. (just a guess)

1 Like

The bridge is a collection of simple boxes aligned next to each other. The dominoes are simple boxes. I will try a bridge of just one box. Thanks!

1 Like

I’ve tried I single box for the bridge, the linear velocity noise is then gone but there is still angular velocity noise (much much much less but still). After a minute the dominos have rotated a little as shown in the pic.

I guess the bridge body is static (mass = 0) ?

I think you’ll get a different behavor with ammojs. Did you try to force bodies to sleep? Body - cannon

I mean it should just “work”

Whats the scale of your scene, try upping everything by a factor of 10 to get rid of some of the float error.

1 Like

Yes, bridge is static. Stuck with Cannon for now. I will try sleep. Thanks.

Squares are 100x100, dominos are 3x6x1.

Sleep does not help.
BTW, what is the best way to undo a collision? (revert position and rotation?). I can reset the velocity onCollide() but the dominoes have already been moved.

It doesn’t really make sense to undo a collision. Physics engine has to compute and move body according to the penetration. You can set linear/angular velocities to 0 but the body will already be moved and the rotation/jiterring will be present.
Is it possible to create the physics impostors on demand? like only those around the latest collision?

I’m just confused why my example they are sitting still, but with yours they are moving. That’s odd.

I will play around with your example. Thanks for providing that great trimmed down PG.

Agree but I was looking for a hack to solve the issue for now. I will look into the on-demand solution.

This is embarrassing. The problem was that the first brick knocked over was being knocked over not just once but periodically. This shouldn’t cause the other bricks to move but when I fixed that bug the dominoes stay put. Sorry for wasting your time.