Basic working with physics

Hi, I have a problem with the quality of Physics simulation, I am using AmmoJSPlugin. A simple scene contains a sphere and should collide with the mesh terrain, how you can see on the picture. The problem is,

  1. the sphere is too bellow in the object surface. Sometimes it’s okay, but other times it’s partially immersed and under the mesh of object. Is there any tutorial, how to prepare mesh for good results if we are working with Physics…? This is like “hocus pocus”. How can I know their requirments for good results…

  2. Even though the ball is in the valley and its should to stand, it is still spinning and moving slightly.

Pinging @cedric and @RaananW

Hi!

If your sphere is moving too fast, you can increase the iteration count per frame using substeps.

https://doc.babylonjs.com/how_to/using_advanced_physics_features#substeps

But this will only fix collision detection if your sphere moves too fast and passes thru the ground.

Hello Cedric. I tried substeps, see my source code down. But I have the same problem. The ball passes through the terrain or partially. It most often moves under the terrain. It does not fall but is under the ground. Any other ideas on how to normalize the simulation process, please?

if (evt.sourceEvent.key == “f”) {

            scene.enablePhysics(null, new BABYLON.AmmoJSPlugin());

            teren.physicsImpostor = new BABYLON.PhysicsImpostor(teren, BABYLON.PhysicsImpostor.MeshImpostor, {mass: 0, friction: 0, restitution: 0.3});

            sphereMetal.physicsImpostor = new BABYLON.PhysicsImpostor(sphereMetal, BABYLON.PhysicsImpostor.SphereImpostor, {mass: 0.1});

            var physicsEngine = scene.getPhysicsEngine();

            physicsEngine.setSubTimeStep(1);
    }

Can you provide a PG please?

Its my code:

https://playground.babylonjs.com/#MZ6G3S#1

but it does not work like in VisualStudio Code… Probably you will be much more clever.

I tweak your PG https://playground.babylonjs.com/#MZ6G3S#2
I changed the scene to use right handed system because of a scale -1 on Z
and I changed the scale of the mesh. For this last change, I have to take a closer look.
I don’t see why there is a issue with it yet.

1 Like

Hi Cedric,

thank you very much for your answer! The solution of my problem., seems to have been hidden in this line:
scene.useRightHandedSystem = true;

When I run a ball simulation, one thing is weird. The ball should, after a while, remain standing in the valley - the lowest point of terrain. But the ball is still on the move, every time in motion - for hours and that is not very realistic. I tried to sett properties like: friction, mass, restitution … but I didn’t get a good result. Where is this secret hidden? Thanks.