Thanks Tiblanc, but I'm not interested in discussing how to deal with the game loop/game logic. I'm interested in the numerical stability of the physics system in a game with variable frame rate.
I would understand if this problem could be addressed, discussing possible solutions. Of course if Erin is interested to modify Box2D to support this sort of feature (maybe with some contributed patch).
The problem could be solved in two ways:
- modify b2Body to be able to read an set the current force/torque. This is the most simple solution and allows to solve the problem outside Box2D.
- update Box2D b2World::Step() with a flag to know if it have to reset applied forces. This allows to perform minor physics logic (as controllers) between subsequent calls to Step() (in the same game tick).
As side note, solution 2 requires that all internals of Box2D (as collision responses) deal with impulses and not with forces, otherwise they can accumulate. From what i can see from the sources, Box2D works already with impulses, so this should not be a problem.
Solved the previous problem, the
interpolation phase can be implemented outside Box2D; or Box2D can be extended (as Bullet) storing, in b2Body, the previous state (position/rotation). In this case could be implemented a new Step() method that implements the whole logic, maybe with a callback to execute custom physics controllers/logic between the single simulated steps.
Solution 1 is the most simple to implement: a couple of simple accessor methods in b2Body.
Could be Erin interested in a patch for solution 1?