Problem when simulating physics with different timesteps

onne
Posts: 4
Joined: Mon Feb 10, 2014 12:25 pm

Problem when simulating physics with different timesteps

Post by onne »

Hi,
I am doing some tests where I use a custom force to simulate gravity. For me it seems that the clearForces() is placed badly in the btDiscreteDynamicsWorld::stepSimulation() function... But obviously there must be something I am missing. (I am running the 2.82)

So I have this kind of setup for a simple test:

Common setup:
- I drop a ball of 10 kg and see where it is in certain time.
- Physics fixed time step is 1/60 s
- I use the preTickCallback() to apply the custom force (gravity)

1. simulate 3 seconds(in realtime) with delta time 1/60
2. speed up: simulate 1 second(in realtime) with delta time 1/60 * 3
3. slow motion: simulate 6 seconds(in realtime) with delta time 1/60 * 0.5

in my understanding the ball should end up roughly in the same position for all the cases.

Now for the problem:
If I would modify the stepSimulation() by moving the clearForces() call to the end of the "for (int i=0;i<clampedSimulationSteps;i++)" loop - everything seems fine.

But with the normal code (without any modifications to bullet library), for the #2 I need to scale the applied forces by 1/3. The #3 is working ok, although If in my game loop I add other forces while in slow motion, half of those disappear because of the clearForces() is run always(not only after the simulation).

So I have a kind of a solution, but I am wondering if there might be some weird side effects.
onne
Posts: 4
Joined: Mon Feb 10, 2014 12:25 pm

Re: Problem when simulating physics with different timesteps

Post by onne »

Hmh, with that change also the default applyGravity should be put there. I guess my problem is that I should not use the preTickCallback() for adding custom forces in the first place... or alternatively I should clear those in the post callback.