# Basic working with physics

**URL:** <https://forum.babylonjs.com/t/basic-working-with-physics/10747>\
**Category:** Questions\
**Created:** [May 11, 2020, 4:36pm UTC](https://forum.babylonjs.com/t/basic-working-with-physics/10747 "2020-05-11T16:36:09Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![Johny\_Mickey](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/johny_mickey/32/24948_2.png) [@Johny\_Mickey](https://forum.babylonjs.com/u/Johny_Mickey)\
**Post date:** [May 11, 2020, 4:36pm UTC](https://forum.babylonjs.com/t/basic-working-with-physics/10747/1 "2020-05-11T16:36:09Z")

</div>

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.

 ![pic](https://us1.discourse-cdn.com/flex024/uploads/babylonjs/original/2X/e/efd47c645318e481e18cd5074123d73ee03505b0.jpeg)

---

<div class="post-metadata">

**Author:** ![Deltakosh](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/deltakosh/32/26635_2.png) [@Deltakosh](https://forum.babylonjs.com/u/Deltakosh)\
**Post date:** [May 11, 2020, 4:59pm UTC](https://forum.babylonjs.com/t/basic-working-with-physics/10747/2 "2020-05-11T16:59:54Z")

</div>

Pinging @cedric and @RaananW

---

<div class="post-metadata">

**Author:** ![Cedric](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/cedric/32/2742_2.png) [@Cedric](https://forum.babylonjs.com/u/Cedric)\
**Post date:** [May 11, 2020, 5:20pm UTC](https://forum.babylonjs.com/t/basic-working-with-physics/10747/3 "2020-05-11T17:20:55Z")

</div>

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](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.

---

<div class="post-metadata">

**Author:** ![Johny\_Mickey](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/johny_mickey/32/24948_2.png) [@Johny\_Mickey](https://forum.babylonjs.com/u/Johny_Mickey)\
**Post date:** [May 11, 2020, 6:27pm UTC](https://forum.babylonjs.com/t/basic-working-with-physics/10747/4 "2020-05-11T18:27:27Z")

</div>

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);
    }
```

---

<div class="post-metadata">

**Author:** ![Cedric](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/cedric/32/2742_2.png) [@Cedric](https://forum.babylonjs.com/u/Cedric)\
**Post date:** [May 11, 2020, 6:46pm UTC](https://forum.babylonjs.com/t/basic-working-with-physics/10747/5 "2020-05-11T18:46:31Z")

</div>

Can you provide a PG please?

---

<div class="post-metadata">

**Author:** ![Johny\_Mickey](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/johny_mickey/32/24948_2.png) [@Johny\_Mickey](https://forum.babylonjs.com/u/Johny_Mickey)\
**Post date:** [May 11, 2020, 7:24pm UTC](https://forum.babylonjs.com/t/basic-working-with-physics/10747/6 "2020-05-11T19:24:56Z")

</div>

Its my code:

[https://playground.babylonjs.com/#MZ6G3S#1](https://playground.babylonjs.com/#MZ6G3S#1)

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

---

<div class="post-metadata">

**Author:** ![Cedric](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/cedric/32/2742_2.png) [@Cedric](https://forum.babylonjs.com/u/Cedric)\
**Post date:** [May 12, 2020, 9:24am UTC](https://forum.babylonjs.com/t/basic-working-with-physics/10747/7 "2020-05-12T09:24:13Z")

</div>

I tweak your PG [https://playground.babylonjs.com/#MZ6G3S#2](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.

---

<div class="post-metadata">

**Author:** ![Johny\_Mickey](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/johny_mickey/32/24948_2.png) [@Johny\_Mickey](https://forum.babylonjs.com/u/Johny_Mickey)\
**Post date:** [May 13, 2020, 1:52pm UTC](https://forum.babylonjs.com/t/basic-working-with-physics/10747/8 "2020-05-13T13:52:14Z")

</div>

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.
