I’m attempting to get frame interpolation in my game working (just messing around with different types of game loops), and the result is very twitchy entities. I’m not sure if I’m doing this right.
So here it is distilled a bit:
In the update for the entity, it will add its acceleration to its velocity, then its position will be position + velocity.
In the draw for the entity, it will be drawn at position + velocity * interpolation.
The result is an incredibly twitchy entity.
The FPS are generally around 40 and the logic runs at a fixed 25 hz.
Interpolation is calculated like this:
float interpolation = ( now + TIME_BETWEEN_UPDATES - nextUpdate ) / (float) TIME_BETWEEN_UPDATES ;
view.drawView( interpolation );
Can anyone point me in the right direction?
EDIT:
Let me just post my whole loop:
while( loopIsRunning )
{
double now = getTimeInSeconds();
int updates = 0;
while (now >= nextUpdate && updates < MAX_SKIPS)
{
update();
nextUpdate += TIME_BETWEEN_UPDATES;
updates++;
}
view.drawView( (getTimeInSeconds() + TIME_BETWEEN_UPDATES - nextUpdate ) / (float)( TIME_BETWEEN_UPDATES ) );
}