I am using libGDX and I have problems implementing the box2d fixed timestep with interpolation.
This is my code:
private void updateWorld() {
accumulator += Gdx.graphics.getDeltaTime();
while (accumulator>= step) { // The step is 1/10
copyCurrentPosition();
world.step(step, 8, 3);
accumulator -= step;
}
interpolate(accumulator / step);
}
private void copyCurrentPosition() {
prevPosition = new Vector2(player.body.getPosition().x, player.body.getPosition().y);
}
private void interpolate(float alpha) {
player.body.setTransform(player.body.getPosition().x * alpha + prevPosition.x * (1.0f - alpha), player.body.getPosition().y * alpha + prevPosition.y * (1.0f - alpha), 0);
}