Recently the player character in my game has started showing quite noticeable jitter when walking. That is, for one displayed frame he suddenly appears about a half metre further to the left/right than he should be. This is especially visible if I overlay a 1mx1m grid on the screen; while walking, the player normally stays perfectly inside a grid cell as the camera moves with him, but occasionally jumps halfway into the next cell.
I plotted relevant information to track down the source of this jitter:
Attachment:
Screenshot 120316 220221 lg2d.png [ 15.74 KiB | Viewed 540 times ]
The blue line shows the time interval given to b2World::Step() (basically, how long the previous step took), and the green shows how far the player moved. There's an obvious correlation between small spikes in the timestep and large spikes in the X delta, and each of those spikes correspond to a visible jump on the screen. So, it's clear what the cause of the problem is. What I don't know is how to solve it... I don't know how I can smooth my timestep interval to be perfectly uniform, nor how to prevent those small spikes from creating visible jitter. Perhaps I can smooth the displayed position somehow?
(The yellow curved line isn't part of the graph.)
Relevant numbers from the display: Player position (56.1, 4.2) metres, velocity (20.4, 0), Rotation 0°, rendering at 48 FPS, stepping 141 times per second. Rendering takes place in a separate thread. The game renders at 640x480, using GL viewport scaling so that all units are in metres.