What does scene.getPhysicsEngine().setTimeStep() do?

I thought that the timestep of the physics engine was a sort of framerate the physics engine ran at, but in the documentation (Using A Physics Engine | Babylon.js Documentation) it’s mentioned as a way to enter slow motion or make everything faster. But the examples given give the same result as the one without that line. Is it a bug, or is that not what it was meant to do?
If it’s not what it was meant to do, is there an other way to get that result (entering slow motion without making the framerate drop) ?

Adding @RaananW and @Cedric our physix ppl :slight_smile:

Hi @saathvik, welcome to the forum :slight_smile:

It’s not a bug but a difference in the default behavior between the playground, the docs, and the actual code.

The default behavior is to use the engine’s delta (the time between the current and the last frame) to calculate the physics step. In order to set a fixed timestep, you will need to explicitly state that you want to use the timestep instead of the delta. To do that you will need to pass false as the first parameter both either cannon or ammo. For example (with ammo):

Gravity | Babylon.js Playground which changes twice - slow and then fast.

We will need to update the documentation, thanks for letting us know!


Thanks :smile:

I know it’s been a few days, but I just realized - if I change the physics engine to Oimo.js ( new OimoJSPlugin(false) instead of new AmmoJSPlugin(false)) everything behaves weird. After bouncing, the ball spins away to the left, and the timestep doesn’t have any effect on it at all.

Playground - https://playground.babylonjs.com/#2B84TV#22

Adding @RaananW and @Cedric for the physix.

Yep, notice I wrote cannon and ammo and not oimo :slight_smile:
As Oimo hasn’t been changed for quite some time, we honestly don’t fully support it. It’s an issue with the oimo plugin and the way we deal with the timestep. you can submit an issue on github and I will look into it for 5.0.

I submitted the issue - Oimo JS plugin acts weird · Issue #9520 · BabylonJS/Babylon.js · GitHub