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).
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!