# Fixed timestep with interpolation in AS3

I'm trying to implement Glenn Fiedler's popular fixed timestep system as documented here:

http://gafferongames.com/game-physics/fix-your-timestep/

In Flash. I'm fairly sure that I've got it set up correctly, along with state interpolation.

The result is that if my character is supposed to move at 6 pixels per frame, 35 frames per second = 210 pixels a second, it does exactly that, even if the framerate climbs or falls.

The problem is it looks awful. The movement is very stuttery and just doesn't look good.

I find that the amount of time in between ENTER_FRAME events, which I'm adding on to my accumulator, averages out to 28.5ms (1000/35) just as it should, but individual frame times vary wildly, sometimes an ENTER_FRAME event will come 16ms after the last, sometimes 42ms.

This means that at each graphical redraw the character graphic moves by a different amount, because a different amount of time has passed since the last draw. In theory it should look smooth, but it doesn't at all. In contrast, if I just use the ultra simple system of moving the character 6px every frame, it looks completely smooth, even with these large variances in frame times.

How can this be possible? I'm using getTimer() to measure these time differences, are they even reliable?

• Maybe this will help; it's similar but geared to AS3's concerns, those being that Flash is notoriously unreliable when it comes to timing. – Engineer Apr 12 '14 at 2:18
• If you suspect a getTimer() accuracy issue, maybe try using Date.getTime() see if you get any difference? Apparently they can differ: stackoverflow.com/questions/7326315/…. – Laurent Couvidou Oct 9 '14 at 10:02
• Possible duplicate of Android Game-Loop (rendering & logic removed, but still 'skipping frames') - as explained there, this is exactly what happens when naively applying "Fix Your Timestep" to cases where you have an external loop with variances in period (Android, Flash, JS etc.) – Engineer Nov 4 '15 at 9:45
• Hi, did I read correctly? (1) You said that if you move at 6 pixels per frame, things fall apart and look horrible. but if (2) You do the ultra simple thing and move 6px every frame it looks smooth? Are you sure you're explaining this correctly? – AturSams Dec 28 '16 at 9:58
• Are you by any chance, doing semi-fixed and not simply fixed? – AturSams Dec 28 '16 at 9:59