Jump to content
  • Advertisement
Sign in to follow this  
triggdev

Jitter when interpolating sprite from previous position to current physics position

This topic is 760 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) {
    update(physicsStep);
    accumulator -= physicsStep;
}
    
interpolate(accumulator / physicsStep);
renderWorld();

This is update(physicsStep)

prevPosition.set(position);
physPosition.add(velocity.cpy().scl(physicsStep));
bounds.setCenter(physPosition);

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
Advertisement
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:

http://www.sulaco.co.za/opengl_project_Basic_3D_engine.htm

 

 

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

  begin
      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.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!