Skip to main content
Adding summary of information in link
Source Link

To close this question I will take what Vaillancourt said in the comment. This article perfectly describes how to handle physics steps.

And to clarify my other question whether we interpolate between actual and previous physic state then yes we do. It is nicely explained in this post.

Edit:
Because those links can expire I will summarize the most important information here. First, how big should the steps be? They should always be the same size. You can choose whatever number you want but the smaller the more precise it will be in exchange for computing time. But the trick is that you do not want to match frames with steps. I think this code is quite explanatory:

double t = 0.0;
const double dt = 0.01;

double currentTime = hires_time_in_seconds();
double accumulator = 0.0;

while ( !quit )
{
    double newTime = hires_time_in_seconds();
    double frameTime = newTime - currentTime;
    currentTime = newTime;

    accumulator += frameTime;

    while ( accumulator >= dt )
    {
        integrate( state, t, dt );
        accumulator -= dt;
        t += dt;
    }

    render( state );
}

We do as many steps as we can until we would exceed the current time. Which is easy to implement.

The second link explains how to have objects moving even between steps. We cannot extrapolate the movement because we could experience stutter when a collision accures. That is why we have to interpolate between actual physics state and the last physics state using linear interpolation. This allows for smooth motion in exchange for 1 step delay. But because steps are usually 1/60 of second long we do not percieve it much.

To close this question I will take what Vaillancourt said in the comment. This article perfectly describes how to handle physics steps.

And to clarify my other question whether we interpolate between actual and previous physic state then yes we do. It is nicely explained in this post.

To close this question I will take what Vaillancourt said in the comment. This article perfectly describes how to handle physics steps.

And to clarify my other question whether we interpolate between actual and previous physic state then yes we do. It is nicely explained in this post.

Edit:
Because those links can expire I will summarize the most important information here. First, how big should the steps be? They should always be the same size. You can choose whatever number you want but the smaller the more precise it will be in exchange for computing time. But the trick is that you do not want to match frames with steps. I think this code is quite explanatory:

double t = 0.0;
const double dt = 0.01;

double currentTime = hires_time_in_seconds();
double accumulator = 0.0;

while ( !quit )
{
    double newTime = hires_time_in_seconds();
    double frameTime = newTime - currentTime;
    currentTime = newTime;

    accumulator += frameTime;

    while ( accumulator >= dt )
    {
        integrate( state, t, dt );
        accumulator -= dt;
        t += dt;
    }

    render( state );
}

We do as many steps as we can until we would exceed the current time. Which is easy to implement.

The second link explains how to have objects moving even between steps. We cannot extrapolate the movement because we could experience stutter when a collision accures. That is why we have to interpolate between actual physics state and the last physics state using linear interpolation. This allows for smooth motion in exchange for 1 step delay. But because steps are usually 1/60 of second long we do not percieve it much.

Source Link

To close this question I will take what Vaillancourt said in the comment. This article perfectly describes how to handle physics steps.

And to clarify my other question whether we interpolate between actual and previous physic state then yes we do. It is nicely explained in this post.