# AmmoJS forceUpdate does not stop sphere movement

**URL:** <https://forum.babylonjs.com/t/ammojs-forceupdate-does-not-stop-sphere-movement/5501>\
**Category:** Bugs\
**Created:** [September 6, 2019, 2:04pm UTC](https://forum.babylonjs.com/t/ammojs-forceupdate-does-not-stop-sphere-movement/5501 "2019-09-06T14:04:06Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![Null](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/null/32/1947_2.png) [@Null](https://forum.babylonjs.com/u/Null)\
**Post date:** [September 6, 2019, 2:04pm UTC](https://forum.babylonjs.com/t/ammojs-forceupdate-does-not-stop-sphere-movement/5501/1 "2019-09-06T14:04:06Z")

</div>

Hey Guys,

I wanted to signal a bug with the AmmoJS plugin ( perhaps? ) or just physics in general. I have noticed this while trying to switch my game [https://gcapsarena.com](https://gcapsarena.com) ( does not work on chrome now) to the latest version of babylonjs ( I have to since I get an webgl error on chrome).

GCaps is a ball game, I have developed it in 4.0.0.alpha.21 and it worked great. When migrating to the latest version I notice that the ball never stops movement even after setting velocities to 0 or calling forceUpdate on the Impostor. Since GCaps is a multiplayer game you realize that is almost hell to make deterministic. I do not seem to find a solution for this. Luckily, I think I have it reproduced here :

[https://www.babylonjs-playground.com/#B5BDU#66](https://www.babylonjs-playground.com/#B5BDU#66)

If you open the console, you will see that even after calling forceUpdate the spheres position is always changing. forceUpdate resets the impostor so logically it should also reset the forces, something not right.

---

<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:** [September 6, 2019, 2:36pm UTC](https://forum.babylonjs.com/t/ammojs-forceupdate-does-not-stop-sphere-movement/5501/3 "2019-09-06T14:36:43Z")

</div>

Pinging @Cedric

---

<div class="post-metadata">

**Author:** ![Wingnut](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/wingnut/32/53_2.png) [@Wingnut](https://forum.babylonjs.com/u/Wingnut)\
**Post date:** [September 6, 2019, 2:42pm UTC](https://forum.babylonjs.com/t/ammojs-forceupdate-does-not-stop-sphere-movement/5501/4 "2019-09-06T14:42:40Z")

</div>

I bet it’s “Brownian jitter”. Friggin’ Brownians… can never sit still. 🙂

Me thinks maybe… IF AmmoJS has allowSleep and sleepDelay… etc, it’s not activating.

(like I have a clue) 🙂

---

<div class="post-metadata">

**Author:** ![Null](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/null/32/1947_2.png) [@Null](https://forum.babylonjs.com/u/Null)\
**Post date:** [September 6, 2019, 2:49pm UTC](https://forum.babylonjs.com/t/ammojs-forceupdate-does-not-stop-sphere-movement/5501/5 "2019-09-06T14:49:10Z")

</div>

It’s much much worse in my game. There is no jitter, full movement / rotation in force. It used to work in 4.0.0.alpha.21. There is a sleep functionality in ammojs but, as you mentioned, for some reason it is not activated / does nothing. Updating the impostor though re-initializes it, maybe for GC purposes the same physics body is reused?

---

<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:** [September 6, 2019, 3:09pm UTC](https://forum.babylonjs.com/t/ammojs-forceupdate-does-not-stop-sphere-movement/5501/6 "2019-09-06T15:09:59Z")

</div>

I’m taking a look!

---

<div class="post-metadata">

**Author:** ![Wingnut](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/wingnut/32/53_2.png) [@Wingnut](https://forum.babylonjs.com/u/Wingnut)\
**Post date:** [September 6, 2019, 3:17pm UTC](https://forum.babylonjs.com/t/ammojs-forceupdate-does-not-stop-sphere-movement/5501/7 "2019-09-06T15:17:43Z")

</div>

[https://www.babylonjs-playground.com/#B5BDU#71](https://www.babylonjs-playground.com/#B5BDU#71)

I can get that sphere to dead-stop… SOMETIMES. (needs full reloads sometimes?)

MASSIVE code within dual setTimeouts… gruesome! Its got some impostor.setMass(0) calls, which I know Cedric LOVES. 😉

Notice line 29 where I added a few more 9’s to one of the damping values, too. Maybe relevant, maybe not. I think not.

---

<div class="post-metadata">

**Author:** ![Null](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/null/32/1947_2.png) [@Null](https://forum.babylonjs.com/u/Null)\
**Post date:** [September 6, 2019, 4:00pm UTC](https://forum.babylonjs.com/t/ammojs-forceupdate-does-not-stop-sphere-movement/5501/8 "2019-09-06T16:00:13Z")

</div>

@Wingnut These are workarounds. This used to work by setting linear and angular velocities to 0. Also forceUpdate should be the absolute reseter in my opinion. The body should turn to absolute rest when calling it. If not, is there another way to reset the impostor / physicsbody?

@Cedric Thank you so much for having a look!

---

<div class="post-metadata">

**Author:** ![Wingnut](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/wingnut/32/53_2.png) [@Wingnut](https://forum.babylonjs.com/u/Wingnut)\
**Post date:** [September 6, 2019, 4:19pm UTC](https://forum.babylonjs.com/t/ammojs-forceupdate-does-not-stop-sphere-movement/5501/9 "2019-09-06T16:19:53Z")

</div>

> [@Null](#):
>
> These are workarounds.

Yeah, you bet. I just do them… to attempt to find the actual problem area. They’re just garbage “feeling-around-in-the-dark”… but they sure are fun. 🙂 Diggin’ for clues, gettin’ all muddy.

Yep, actual reason for recent functionality changes/differences… needs finding and bug-stomp. 🙂

---

<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:** [September 6, 2019, 4:51pm UTC](https://forum.babylonjs.com/t/ammojs-forceupdate-does-not-stop-sphere-movement/5501/10 "2019-09-06T16:51:02Z")

</div>

Calling forceUpdate will recreate the ammojs rigidbody and collision shape.  
So, setting mass=0 then calling forceUpdate will replace the dynamic body with a kinematic one.  
If you don’t change the mass, I think it’s like setting velocity/angular velocity to 0. So gravity keeps being applied.  
But even with a zero mass, the Y position is updated by the physics engine which is really strange.  
I tried to set the body to sleep without success. I will investigate more on that point.

---

<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:** [September 6, 2019, 5:08pm UTC](https://forum.babylonjs.com/t/ammojs-forceupdate-does-not-stop-sphere-movement/5501/11 "2019-09-06T17:08:24Z")

</div>

Apparently, the delta I get on Y when body has mass == 0 is because of float precision. the difference between 2 frames is \< 10e-5. So, it’s a kinematic object. No need to worry about that.  
But, when in kinematic mode, the impostor will not receive forces from collisions with other bodies.  
That means that other impostors will bounce on it with it will not move. It will be static.

---

<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:** [September 6, 2019, 6:34pm UTC](https://forum.babylonjs.com/t/ammojs-forceupdate-does-not-stop-sphere-movement/5501/12 "2019-09-06T18:34:22Z")

</div>

The body doesn’t go to sleeping mode by itself. I don’t know why yet and it may takes time to figure that out. My guess is that some process keeps touching the body preventing it to sleep.  
Anyway, you can force it to sleep mode:

[https://www.babylonjs-playground.com/#B5BDU#72](https://www.babylonjs-playground.com/#B5BDU#72)

Check line 50.

The position reported will not be the same between two frames. Because of float precision, you’ll get something like 10e-5 delta.

---

<div class="post-metadata">

**Author:** ![Wingnut](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/wingnut/32/53_2.png) [@Wingnut](https://forum.babylonjs.com/u/Wingnut)\
**Post date:** [September 7, 2019, 12:37am UTC](https://forum.babylonjs.com/t/ammojs-forceupdate-does-not-stop-sphere-movement/5501/13 "2019-09-07T00:37:13Z")

</div>

Wanna see something “weird” in that [#72](https://www.babylonjs-playground.com/#B5BDU#72) playground? Try repeated re-RUNS (play button) while watching console.

For me, approximately 1 in 8 re-runs… makes the sphere dead-stop, with no “floaty-floats” at console. Go fig. hmm.

I suppose… Null and I… should help Cedric deep-dive Ammo, if we can. Null, I need you to collect all the “What’s New” lists since 4.0.0.alpha.21. See if you can see anything in the list(s)… that might have caused AmmoJS forceUpdate() to change.

Do you know how to query github… to see all framework PR’s since 4.0.0.alpha.21? That might be worth a tour, too.

Have your report on my desk by Sunday morning, ok? 😃

@trevordev , @RaananW , @JohnK, @Raggar … shall we go digging native Ammo-poop with Cedric?

The more ideas/eyes, the better. Great/Easy physics is a bigtime crowd-drawer for BJS… a very important future-shaper.

Me, I’ll be here, watching you guys… REALLY HARD, and cooking pancakes for us. 🙂

---

<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:** [September 9, 2019, 3:23pm UTC](https://forum.babylonjs.com/t/ammojs-forceupdate-does-not-stop-sphere-movement/5501/14 "2019-09-09T15:23:49Z")

</div>

@Wingnut Once in a while, I get the exact same values between 2 frames. Maybe that’s what you get. It looks like it’s not outputting values.

---

<div class="post-metadata">

**Author:** ![Wingnut](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/wingnut/32/53_2.png) [@Wingnut](https://forum.babylonjs.com/u/Wingnut)\
**Post date:** [September 9, 2019, 7:13pm UTC](https://forum.babylonjs.com/t/ammojs-forceupdate-does-not-stop-sphere-movement/5501/15 "2019-09-09T19:13:44Z")

</div>

[https://www.babylonjs-playground.com/#B5BDU#73](https://www.babylonjs-playground.com/#B5BDU#73)

I’m still getting approx 1-in-8 re-runs… where sphere gets dead-stopped. I’m printing values at 1-second intervals… with time-stamp before each.

I don’t know if this proves/disproves anything, but what the heck… I give it a try. 🙂

I’m seeing various oddness. I tested with .getAbsolutePosition() instead-of .position, too. Oddness. Sometimes X and Z at stopped, but Y is floaty. Then after a few more outputs, Z goes floaty, too, but X still holds-solid. I can’t seem to find a consistent pattern.

Brownian movement… from broken auto-sleep issue, ya think? hmm. Or maybe it CAN’T sleep with those micro-movements happening?

---

<div class="post-metadata">

**Author:** ![Wingnut](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/wingnut/32/53_2.png) [@Wingnut](https://forum.babylonjs.com/u/Wingnut)\
**Post date:** [September 10, 2019, 3:58pm UTC](https://forum.babylonjs.com/t/ammojs-forceupdate-does-not-stop-sphere-movement/5501/16 "2019-09-10T15:58:15Z")

</div>

[https://www.babylonjs-playground.com/#B5BDU#75](https://www.babylonjs-playground.com/#B5BDU#75)

I tried some things. lockedTarget to sphere, changed ground from plane to box, tried less/more impulse power, added texture to ground and zoomed cam… to see if I could see any jitter.

No change. Darn. Still… console numbers show sphere dead stop… 1-in-8 or 1-in-10 re-runs, approx. Floaty-floats the rest of the time. hmm. I don’t know how to help find this issue.

Lines 61/62… I’m not real sure what they do. I’ve “visited” _disableBidirectionalTransformation_ before, which is a fairly new impostor-level property, I think. (within the last 3 years - arrived when transformNodes arrived?)

_physicsBody.setActivationState(2)_… that’s native Cannon level… I have no idea what it does. Maybe @null knows.

---

<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:** [September 10, 2019, 4:06pm UTC](https://forum.babylonjs.com/t/ammojs-forceupdate-does-not-stop-sphere-movement/5501/17 "2019-09-10T16:06:00Z")

</div>

Actually, the sphere has stopped, from an ammojs view. The delta you see is related to float precision.  
The range is 10e-5 and non linear. if the unit is meter, the delta is around 1% of a millimeter.

---

<div class="post-metadata">

**Author:** ![Wingnut](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/wingnut/32/53_2.png) [@Wingnut](https://forum.babylonjs.com/u/Wingnut)\
**Post date:** [September 10, 2019, 4:10pm UTC](https://forum.babylonjs.com/t/ammojs-forceupdate-does-not-stop-sphere-movement/5501/18 "2019-09-10T16:10:04Z")

</div>

But why sometimes dead stop, why other times floaty?

And we still must acknowledge OP. Something changed since 4.0.0.alpha.21… that is making null’s (home project) sphere bounce-around quite severely after the forceUpdate() call, or after the velocities kill, or after a combo of both. He/she says working fine @ 4.0.0.alpha.21.

Something changed… and it’s killing Null’s project. Want to label this as “expected behavior”?

---

<div class="post-metadata">

**Author:** ![adam](https://avatars.discourse-cdn.com/v4/letter/a/4af34b/32.png) [@adam](https://forum.babylonjs.com/u/adam)\
**Post date:** [September 11, 2019, 2:31am UTC](https://forum.babylonjs.com/t/ammojs-forceupdate-does-not-stop-sphere-movement/5501/19 "2019-09-11T02:31:09Z")

</div>

> [@Null](#):
>
> GCaps is a ball game, I have developed it in 4.0.0.alpha.21 and it worked great. When migrating to the latest version I notice that the ball never stops movement even after setting velocities to 0 or calling forceUpdate on the Impostor. Since GCaps is a multiplayer game you realize that is almost hell to make deterministic. I do not seem to find a solution for this. Luckily, I think I have it reproduced here :
> 
> [https://www.babylonjs-playground.com/#B5BDU#66](https://www.babylonjs-playground.com/#B5BDU#66)

It might be a good idea to post this same example using 4.0.0.alpha.21. You could use jsfiddle.

---

<div class="post-metadata">

**Author:** ![Null](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/null/32/1947_2.png) [@Null](https://forum.babylonjs.com/u/Null)\
**Post date:** [September 11, 2019, 4:59pm UTC](https://forum.babylonjs.com/t/ammojs-forceupdate-does-not-stop-sphere-movement/5501/20 "2019-09-11T16:59:56Z")

</div>

For me the problems are bigger. The sphere does not stop at all but for some reason I am unable to reproduce it in the playground. Even with Cedric suggestions ( Thank you so much for them ). Unfortunately I have not been able to understand where the problem is. I have checked the code between BJS versions and it is almost identical. The jitter in this example is not what I am experiencing so I don’t think this is even the case.

I am convinced this is some sort of bug since it used to work before and somehow I am the only one being able to reproduce it. It might be a specific usecase but honestly I am not sure anymore. The same code stops the sphere here and it doesn’t in my project. I will try to set up a scenario as close as mine to be able to reproduce the same thing but to be fair I am losing hope 😕

---

<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:** [September 11, 2019, 5:07pm UTC](https://forum.babylonjs.com/t/ammojs-forceupdate-does-not-stop-sphere-movement/5501/21 "2019-09-11T17:07:10Z")

</div>

Or at least, can you make a video capture of the result and the output values?It might give me some clues on what’s happening.

[Next page](https://forum.babylonjs.com/t/ammojs-forceupdate-does-not-stop-sphere-movement/5501.md?page=2)
