Jump to content
  • Advertisement
Sign in to follow this  

Jitter when interpolating sprite from previous position to current physics position

This topic is 904 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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) {
    accumulator -= physicsStep;
interpolate(accumulator / physicsStep);

This is update(physicsStep)


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.

Edited by triggdev

Share this post

Link to post
Share on other sites
Sounds like a floating point precision error. There is probably a division happening somewhere where the denominator is really close to 0

Share this post

Link to post
Share on other sites

How would that affect interpolation? Or cause it to slow down? Wouldn't floating point precision errors be very tiny and usually not noticeable

Share this post

Link to post
Share on other sites

you could use average of times between frames (last and present) divide that by two that should smooth the movement. its shown here:




however i managed to make something diffrent but i cant remember what (i believe i used bigger precission timer)

      Inc(FPSCount);                      // Increment FPS Counter

      FrameTime := GetTickCount() - ElapsedTime - DemoStart;
      LastTime :=ElapsedTime;
      ElapsedTime :=GetTickCount() - DemoStart;     // Calculate Elapsed Time
      ElapsedTime :=(LastTime + ElapsedTime) DIV 2; // Average it out for smoother movement

Edited by WiredCat

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!