Greetings,
I tried implementing the gafferongames logic as well, but also had extreme jerkiness. After countless hours tweaking and searching, I found this post and it works best for me (no jerkiness):
viewtopic.php?f=4&t=3027 (2nd post down).
Code from that post:
It's worth noting that this is more of a fixed-variable timestep solution. It processes a variable timestep unless more than 2*timestep time has passed, in which case it processes the timestep in discreet fixed timesteps (and then does a varaible timestep with the remainder). I also have pre and post timestep processing that I do before and after both Steps (the one in the loop and the one after the loop).
Another useful addition (that I did get from gafferongames) was to clamp the deltasec to a reasonable amount (like .25 secs). That way if the game is paused for a long, long time (and then resumed) I am not waiting forever for the physics to catchup. (I just toss the whole deltasec value (if > 0.25) and set the deltasec to the fixed-timestep. Seems to work very well...
So here's my question:
My main concern here is the iteration counts. Right now they are always 10 and 10 for both Steps.
Since the varaible timestep can be just under 2*tmesteps in length, should I increase the iterations by a factor so that longer (variable) timesteps get more iterations and small fractional (variable) timesteps get fewer iterations? The hope would be that it would allow collisions to be more accurate (and avoid tunneling) when the (variable) timestep is larger. But not understanding the box2d internals makes me wonder if there would be unexpected side effects that might not be immediately apparent.
Regards,
Q
I tried implementing the gafferongames logic as well, but also had extreme jerkiness. After countless hours tweaking and searching, I found this post and it works best for me (no jerkiness):
viewtopic.php?f=4&t=3027 (2nd post down).
Code from that post:
Code:
double max = _dt*2.0;
while (deltasec>=max && !_quit)
{
m_world->Step((float)_dt, _iters);
deltasec -= _dt;
}
m_world->Step((float)deltasec, _iters); //This syncs up the physics engine to the current frame
while (deltasec>=max && !_quit)
{
m_world->Step((float)_dt, _iters);
deltasec -= _dt;
}
m_world->Step((float)deltasec, _iters); //This syncs up the physics engine to the current frame
It's worth noting that this is more of a fixed-variable timestep solution. It processes a variable timestep unless more than 2*timestep time has passed, in which case it processes the timestep in discreet fixed timesteps (and then does a varaible timestep with the remainder). I also have pre and post timestep processing that I do before and after both Steps (the one in the loop and the one after the loop).
Another useful addition (that I did get from gafferongames) was to clamp the deltasec to a reasonable amount (like .25 secs). That way if the game is paused for a long, long time (and then resumed) I am not waiting forever for the physics to catchup. (I just toss the whole deltasec value (if > 0.25) and set the deltasec to the fixed-timestep. Seems to work very well...
So here's my question:
My main concern here is the iteration counts. Right now they are always 10 and 10 for both Steps.
Since the varaible timestep can be just under 2*tmesteps in length, should I increase the iterations by a factor so that longer (variable) timesteps get more iterations and small fractional (variable) timesteps get fewer iterations? The hope would be that it would allow collisions to be more accurate (and avoid tunneling) when the (variable) timestep is larger. But not understanding the box2d internals makes me wonder if there would be unexpected side effects that might not be immediately apparent.
Regards,
Q