Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

An object - a player or npc or whatever - has a position, direction and speed and such.

Before drawing each frame, we want to compute the current position of each object.

How do you do this?

If you take the elapsed time since last frame, you run the very real risk of the game running at the wrong speed if the frame-rate is very fast and the clock precision poor (as it often is on some platforms).

And how can you incorporate player controls such as the player wanting to go left or right (e.g. in a simple asteroids clone without ship inertia)?

share|improve this question
I don't know any platform that doesn't offer sub-millisecond clock precision. What do you mean by "as it often is on some platforms"? –  Sam Hocevar May 18 '12 at 10:17
@SamHocevar Google Native Client has been giving me problems; people have even managed to jump to ledges they shouldn't etc. –  Will May 18 '12 at 10:52
So you mean that position += direction * speed * elapsed is giving you problems? –  David Gouveia May 18 '12 at 11:15
@DavidGouveia yes; hence wondering what other approaches work better –  Will May 18 '12 at 11:45
If your problem is the frame rate becoming too high, how about modifying your game loop to enforce a fixed frame rate? gafferongames.com/game-physics/fix-your-timestep –  David Gouveia May 18 '12 at 11:51

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.