moveWithCollisions() vibration issue

Hi, I think this may be a bug in Babylon but not 100% sure… Check the playground here: https://playground.babylonjs.com/#8MNKEC#2

In this example, when the sphere collides with the box at any speed between 10 to 25, it vibrates in place. Below 10 the object simply doesn’t move, and above 25 there is no issue with collision or vibrating…

This is affecting our app as well due to gravity on avatars under certain conditions (ie a certain gravity and frame rate), but the playground above is the simplest way to reproduce the issue…

That’s not a bug in babylon per se, it is the design of the collision system which has a form of throw-back. if you are colliding against an enabled mesh. It will throw you back in the other direction of the collision. You can change the behavior if you change the variable BABYLON.Engine.CollisionsEpsilon;
For example:
BABYLON.Engine.CollisionsEpsilon = 0.00000001;

Will prevent the throw back in your case. Your velocity values are very small, and the values between 10 and 25 are simply within the threshold.

1 Like

So do I just have to find the right number for this field so that the vibrating stops? What does this field actually do? Also, is there a way to turn off “throw back”, since I assume that means a bounce? We don’t need any bouncing for our use case…

Well, I just showed you how :slight_smile:

The default value makes sense to the usual use-cases. The collision system needs to be adjusted to your scene, the units you are using etc’. The default ellipsoid is 1,1,1, for example. I am sure it doesn’t fit use cases in a very small scene. it needs to be adjusted, and you are the one that know your scene the best.

Hmm, it kind of works in the playground but I can’t find a good value of this field in our app to entirely prevent the vibrating issue, it just seems to change the frame rate at which the issue occurs… Is there a way to turn off the throw back? This field doesn’t seem to do that…

FYI I think I’ve solved this in our app by doing this:

  • Set CollisionsEpsilon to 0.00005
  • Run the physics loop with a fixed frame delta value of 60FPS (1/60)
  • Run the physics loop multiple times per frame to match the frame rate, in the case where the frame rate is not 60FPS (this prevents the user moving slower when the frame rate is slower, faster when frame rate is faster, etc)
  • Key part: between each physics loop run computeWorldMatrix(true) on the moving object to force the world matrix to update between each iteration of the physics loop. Without this, it oddly behaved as if the physics loop had only a single iteration and a flexible frame delta…

I think I also know why there’s a push-back in the first place; Babylon seems to move the object to the final position and then push it back, instead of colliding first and interrupting the full movement… This explains why the push-back has to exist…

Anyway, it’s working now with no vibration, thanks for the help understanding the issue :+1:

2 Likes