We're using Box2D for our iPhone game and our player's b2Body was shaking back and forth when moving. We tracked the problem down to the fact that we were applying a variable time step to boxWorld->Step.
We were following code we've seen commonly used in the Box2D community so were surprised that this was a problem. Here's the code calling Step:
We pass the actual time between frames which caused the b2Body to shake (app runs at 60 fps). With a constant step = 1.0/60.0, the shaking goes away.
So our questions to the community are these.
1) If the above variable step code is common in the Box2D community, then why does our fairly simple app have a problem with shaking?
2) Is there something we should be doing different so we can have a variable time step?
3) What is the norm for iPhone games using Box2D: variable or constant time step?
Thanks
We were following code we've seen commonly used in the Box2D community so were surprised that this was a problem. Here's the code calling Step:
Code:
-(void) increment: (ccTime) step {
//It is recommended that a fixed time step is used with Box2D for stability of the simulation, however, we are using a variable time step here.
int32 velocityIterations = 8;
int32 positionIterations = 1;
// Instruct the world to perform a single step of simulation. It is generally best to keep the time step and iterations fixed.
boxWorld->Step(step, velocityIterations, positionIterations);
}
//It is recommended that a fixed time step is used with Box2D for stability of the simulation, however, we are using a variable time step here.
int32 velocityIterations = 8;
int32 positionIterations = 1;
// Instruct the world to perform a single step of simulation. It is generally best to keep the time step and iterations fixed.
boxWorld->Step(step, velocityIterations, positionIterations);
}
We pass the actual time between frames which caused the b2Body to shake (app runs at 60 fps). With a constant step = 1.0/60.0, the shaking goes away.
So our questions to the community are these.
1) If the above variable step code is common in the Box2D community, then why does our fairly simple app have a problem with shaking?
2) Is there something we should be doing different so we can have a variable time step?
3) What is the norm for iPhone games using Box2D: variable or constant time step?
Thanks