Box2D Forums

It is currently Mon May 20, 2013 10:17 am

All times are UTC - 8 hours [ DST ]




Post new topic Reply to topic  [ 3 posts ] 
Author Message
 Post subject: Jittery position updates
PostPosted: Fri Mar 16, 2012 9:25 pm 
Offline

Joined: Sat Feb 05, 2011 8:51 pm
Posts: 30
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
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.


Top
 Profile  
 
PostPosted: Fri Mar 16, 2012 10:20 pm 
Offline
Site Admin

Joined: Thu Sep 06, 2007 12:34 am
Posts: 2931
There seems to be a correlation between your time step and the position delta, which makes sense to me. Having a noisy timestep means your frame time predictions are inaccurate, leading to non-smooth movement.


Top
 Profile  
 
PostPosted: Fri Mar 16, 2012 10:24 pm 
Offline

Joined: Sat Feb 05, 2011 8:51 pm
Posts: 30
Yes, I'm just not sure how to go about fixing that...


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 3 posts ] 

All times are UTC - 8 hours [ DST ]


Who is online

Users browsing this forum: No registered users and 4 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Powered by phpBB® Forum Software © phpBB Group