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\$
5
  • \$\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
    Commented Apr 12, 2014 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\$ Commented Oct 9, 2014 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
    Commented Nov 4, 2015 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\$
    – AturSams
    Commented Dec 28, 2016 at 9:58
  • \$\begingroup\$ Are you by any chance, doing semi-fixed and not simply fixed? \$\endgroup\$
    – AturSams
    Commented Dec 28, 2016 at 9:59

1 Answer 1

-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\$
1
  • \$\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
    Commented Feb 10, 2014 at 21:24

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .