Jitter when interpolating sprite from previous position to current physics position

Started by
2 comments, last by _WeirdCat_ 7 years, 10 months ago

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.

Advertisement
Sounds like a floating point precision error. There is probably a division happening somewhere where the denominator is really close to 0
My current game project Platform RPG

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

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

This topic is closed to new replies.

Advertisement