Frame Rate Independent Movement Box2Das3

I've added a trace in to make sure that I'm getting the right values for iInterpolation:

Code:
         iInterpolation = (iAccumulator/millistep);
         trace("iInterpolation is "+iInterpolation+" - ("+iAccumulator+'/'+millistep+')');


And here's the output from that:

Code:
iInterpolation is 0.25 - (5/20)
iInterpolation is 0.45 - (9/20)
iInterpolation is 0.65 - (13/20)
iInterpolation is 0.85 - (17/20)
iInterpolation is 0.05 - (1/20)
iInterpolation is 0.85 - (17/20)
iInterpolation is 0.05 - (1/20)


So it's not that iInterpolation is set to a negative value - but the fact that you might have thought that now leads me to think that I'm doing something wrong somewhere else...
Just digging through my code for this and realised I was doing something incredibly stupid which was the reason for this not working - instead of doing:

UpdatePhysics();
UpdateSpritePlacements();

I was doing it the other way around which of course meant that the interpolation being done was just wrong causing the jitteryness. Now that the functions are the right way around, it works perfectly.

Thanks for everybody's help with making this work!
Well done andrew, this is something im about to try and tackle... any chance you could post your final code?

and how are you doing the interpolation ?
No problem, BorisTheBrave and VengantMjolnir pretty much spelled it out for me and I was still doing it wrong which is a bit embarrassing!

Each of my Box2D objects derives from a class which has this function to update it's display:

Code:
      protected function UpdateDisplayClip(aPosition:b2Vec2,aRotation:Number)
         {
         var newX = aPosition.x*30;
         var newY = aPosition.y*30;
         var newAngle = aRotation;
         iDisplayClip.x = (newX - iOldX) * CMapBox2D.iInterpolation + iOldX;
         iDisplayClip.y = (newY - iOldY) * CMapBox2D.iInterpolation + iOldY;
         iDisplayClip.rotation = (newAngle - iOldRotation) * CMapBox2D.iInterpolation + iOldRotation;
         iOldX = newX;
         iOldY = newY;
         iOldRotation = newAngle;
         }


Note that CMapBox2D.iInterpolation is a static number variable set by the object which does the world.step() function.

And here's the code which does the world.step()

Code:
      protected function DoMapUpdate()
         {
         const millistep:int = 20;
         const timestep:Number = millistep/1000;
         const iterations:int = 20;
         const iterationsb:int = 20;
         var thisTime = getTimer();
         iAccumulator += thisTime-iPrevTime;
         var step:Number = (thisTime-iPrevTime)/1000;
      
         iPrevTime = thisTime;
         while(iAccumulator>=millistep)
            {
            iWorld.Step(timestep,iterations,iterationsb);
            iAccumulator -= millistep;
            }
         iInterpolation = (iAccumulator/millistep);
         }


I'm using revision 50 from the SVN repository.
thanks very much 😀

Original thread: https://box2d.org/forum/viewtopic.php?t=4008