I have dynamically generated terrain that scrolls to the side that I made using this tutorial:
However, as the terrain scrolls to the left it occasionally jumps and is just not smooth at all. The performance is running at 55-60 fps and 4 draw calls, so I’m confused as to what the issue could be.
The problem is that, for the most frames, the world update only runs once. The remainder keeps getting added to the accumulator until the value in the accumulator is greater than or equal to 2/60. In that case the world update runs twice and you get the occasional jumps, because your world is one frame ahead of the view. You can try this hypothesis by having a console output every time the world update runs twice.
A possible fix is to make the update interval much shorter, so the world won’t get ahead by 1/60 seconds.
I tried lowering the update interval and it didnt do much. I’m looking at the interpolation implementation that dotsquid posted and it all makes sense except I’m confused what the PhysicsComponent in the code is exactly.
If you have a fixed timestep of 1/60 box2d and you step the world every 1/30 of a second then box2d “thinks” that 1/60 of a second went buy which is wrong. What you want to do is to calculate the actual elapsed time between two frames and step the world not once but so many times that the actual difference is very small.
Also you dont want to set positions to the bodies directly. Rather interpolate to the next position.