Differences between physics plugins

Hello!

I’m facing some strange behavior regarding the physics plugins. I will try to separate my issue in separate parts to ease the comprehension a bit.

First of all, I was able to create a pool game using CannonJS as a physic plugin. According to some situations, I had some issues where some balls were going through other entities. In order to fix this issue, I simply changed the physics steps. However, this slowed the whole process and make the game a bit more glitchy (especially on mobile).

I decided to switch to AmmoJS since it supports CCD (Continuous Collision Detection). The previous issues mentionned above are now both fixed (no more glitches and no more balls going through other entities). :grin:

To fix this I simply add this to my balls :

myBallMesh.physicsImpostor.physicsBody.setCcdMotionThreshold(myValue)

However, I guess that AmmoJS is not calculating physics like CannonJS because the balls does not have exactly the same behavior as previously. One major issue that I’m now facing is regarding the friction. The balls are now sliding on the table instead of rolling. I took a look at the documentation and I saw setRollingFriction() which is expecially used for sphere. Even when I used this, the ball behaviour is strange. When the white ball hit another ball, the other ball slide for a moment and then, start to roll. I would simply like it to roll all the time just when I was using CannonJS.

Take note that the only thing that I change in the code was that instead of importing CannonJS, I’m simply importing AmmoJS like this :

const ammo = await Ammo()
const gravityVector = new Vector3(0, -9.8, 0)
const physicsPlugin = new AmmoJSPlugin(true, ammo)
scene.enablePhysics(gravityVector, physicsPlugin)
scene.collisionsEnabled = true

And that I added this to my balls to try to have a real friction simulation:

myBallMesh.physicsImpostor.physicsBody.setRollingFriction(0.3)
myBallMesh.physicsImpostor.physicsBody.setCcdMotionThreshold(0.2)

Furthermore, when I create a PhysicImpostor, I can set the mass, friction and restitution. When using AmmoJS, I can also set the friction and restitution of the PhysicsBody. I don’t quite understand the purpose behing that. How can an object have two different friction and restitution? I play a bit with it and it seems like the friction of the PhysicsBody altered the friction of the PhysicsImpostor.

My question : How can I have a sphere rolling on a plane/box using AmmoJS and BabylonJS and can someone explain to me the PhysicImpostor/PhysicBody friction and restitution difference ?

Thanks a lot! :wink:

Add @carolhmj and @Cedric

It seams about right!
:rofl::rofl::rofl:

I know this is very childish but could not help it! - sorry

1 Like

LOL I feel so bad I did not caught this one :slight_smile:

Lol… I did not have that in mind while writing this. :sweat_smile:

Hey there!

Hmmm I would say this is an unintended side effect of the way the current Physics API is written. More modern engines have this concept of separating physics bodies and collision shapes, but the current API treats them as one and the same. Fortunately, the new API coming with 6.0 has solved this problem :slight_smile:

friction and restitution methods from the PhysicsImpostor are abstract of body methods. in other words, the impostor methods will call the body methods.

How can I have a sphere rolling on a plane/box using AmmoJS and BabylonJS

Simply add an impulse and it should roll like in this PG:

1 Like