4
\$\begingroup\$

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?

\$\endgroup\$
  • \$\begingroup\$ 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. \$\endgroup\$ – Engineer Apr 12 '14 at 2:18
  • \$\begingroup\$ 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/…. \$\endgroup\$ – Laurent Couvidou Oct 9 '14 at 10:02
  • \$\begingroup\$ 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.) \$\endgroup\$ – Engineer Nov 4 '15 at 9:45
  • \$\begingroup\$ 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? \$\endgroup\$ – wolfdawn Dec 28 '16 at 9:58
  • \$\begingroup\$ Are you by any chance, doing semi-fixed and not simply fixed? \$\endgroup\$ – wolfdawn Dec 28 '16 at 9:59
-1
\$\begingroup\$

Check this out :https://stackoverflow.com/questions/20192775/box2d-frim-frame-rate-independent-movement/20283264#20283264 . Try using a filtered variable time step... if you can.

\$\endgroup\$
  • \$\begingroup\$ Unfortunately I can't, I absolutely have to use a fixed time step because there's a networking element to what I'm doing, and what happens in each step is very complicated, aside from the movement. \$\endgroup\$ – Jim Sreven Feb 10 '14 at 21:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.