setSleepingThresholds not working

Hi,

I’m building a two wheels robotics simulator here https://gears.aposteriori.com.sg but noticed that the robot keeps sliding along the floor very slowly even when the wheels are not turning. I made a simple playground here https://playground.babylonjs.com/#IMD13Q#3 that demonstrates the problem (…the movement is very slow and can be hard to see).

I’m guessing that it’s a artifact cause by floating point inaccuracy, and have tried using setSleepingThresholds, but it doesn’t seem to do anything. I would have expected setSleepingThreshold to completely stop the body if movement is below the threshold. Am I understanding it wrong?

I’ve also tried setDamping, which reduces the sliding but does not eliminate it. It also messes with the movement of the robot when it is meant to move.

Other things I’ve tried unsuccessfully includes:

  • Setting a high friction
  • SetMotor(0) to stop wheels from turning (…wheels still turn slowly)
  • Actively control the wheels to ensure the wheels stay in position (…wheels no longer turn, but the robot still slides along the floor)

Is there anyway to make the body sleep and stay perfectly still if the velocity is below a certain threshold?

Maybe @RaananW or @Cedric can help with physics :slight_smile:

I tried to tweak the mass to lower values, increase friction, increased sleepthreshold… I still get a slow movement.Even when setting linearvelocity to 0… :frowning:

Digging through bullet’s documentation, it seems that setSleepingThresholds works together with setDeactivationTime. As setDeactivationTime is missing in ammo.js, that may be the reason why setSleepingThresholds isn’t working. I’m really not sure about this as a default deactivation time may have been set internally by ammo.

I’ve tried using physicsBody.getWorldTransform().getOrigin() to save the position of the physics body, and setting it back if velocity is below a certain threshold. Not perfect, but seems to work well enough https://playground.babylonjs.com/#IMD13Q#5

The body still wiggle around a bit, but it’s no longer cumulative due to the position reset. It occasionally wiggles too much, exceeds the threshold, and move out of position, but that can be alleviated by raising the threshold (…at the expense of affecting low speed movement).

If anyone can suggest a better approach, it’ll be greatly appreciated.

1 Like