How can I implement "time compression" in box2d physics engine?

129 Views Asked by At

I am implementing a game in Andengine using physics. The physics looks quite real, but the game feels slow and boring. Is there any way to change the physics engine timing in case I want to implement some time compression, like fast forward, or slow motion?

The only way I figured to do it is overriding the onUpdate method of PhysicsWorld and multiplying elapsed seconds by a factor, but Im afraid of being spoiling some internal calculation of the engine.

@Override
public void onUpdate(final float pSecondsElapsed) {
    super.onUpdate(pSecondsElapsed * mTimeCompression);
}
1

There are 1 best solutions below

0
squire On

(This should probably be a comment but I don't have enough rep yet.)

I think that your suspicion about spoiling the internal calculations is correct - see: https://gafferongames.com/post/fix_your_timestep/

A similar question was asked and the solution involves calling step (which seems to be onUpdate in your case) multiple times rather than changing the time step itself: Is it possible to fast forward simulation in Box2D