I recently separated my render timestep from the physics timestep. Physics is running at 20hz and the client interpolates the sprite position from the previous position to the current physics position every render call. I'm using a technique from http://gafferongames.com/game-physics/fix-your-timestep/. This code is in the render(delta) call.
if (delta > 0.25f) delta = 0.25f;
accumulator += delta;
while (accumulator >= physicsStep) {
update(physicsStep);
accumulator -= physicsStep;
}
interpolate(accumulator / physicsStep);
renderWorld();
This is update(physicsStep)
prevPosition.set(position);
physPosition.add(velocity.cpy().scl(physicsStep));
bounds.setCenter(physPosition);
This is interpolate(alpha)
position.set(prevPosition).lerp(physPosition, alpha);
It renders smoothly most of the time, but as I said everyone once and a while the character will start to jitter. It becomes smooth again after a while. Any ideas on how to deal with this?
I've been messing with it and the jitter is being caused by the interpolation "slowing down" right before it reaches the target position (current physics position). It doesn't slow down when it runs smoothly, only when it jitters.
Also, it only jitters if alpha in the interpolation method never gets to be above 0.9.