Here in this article there is a nice explanation that velocity iterations and position iterations settings affect the way bodies will react when they collide, and step affects on speed and how gravity acts. So the precision is hidden behind position and velocity iterations, whereas you need to have the world step to advance the time in physics world. I also know that step should be constant to be able to have consistent and debug-able game physics. Hence I do this (where dt
is FPS delta time):
if (m_world.GetBodyCount() > 0)
{
static const double step = 1.0 / 70.0;
static double accumulator = 0.0;
// max frame time to avoid spiral of death
if ( dt > 0.25 )
dt = 0.25;
accumulator += dt;
while (accumulator >= step)
{
m_world.Step(step, VELOCITY_ITERATIONS, POSITION_ITERATIONS);
accumulator -= step;
}
}
So I guess the step should not be less then FPS minimum value to avoid discrete simulation (cutting effects). Usually FPS is 1/60.0 hence I have chosen 1/70 as a step to have the best performance. And as Velocity and Position iterations I use 6 and 2 respectively which turned to be enough for collisions till today. Is my logic correct or I miss something? Is there a way to optimize more? What are the recommended values for this parameters for mobile games (considering that the game should work on week devices too). Should I use non-constant velocity iterations and position iterations reducing them when FPS drops?