[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

Re: [pygame] frame independant movement



On Wed, Feb 3, 2010 at 3:30 PM, R. Alan Monroe <amonroe@xxxxxxxxxxxxxxx> wrote:
> The nice thing about limiting the framerate versus having calculations be
> done based on time passed is that it is much more consistent. With dt
> calculations you will often get huge jumps on slower computers and extra
> slow movement in cases on fast machines, just do to inaccuracies and error
> in the calculation.  On a slower machine, no matter which timing method you
> use it will be unpleasant.

What kind of innacuracies, specifically?

Any time-step based integration of non-linear functions will have errors and inaccuracies, which are larger the larger the time-step is.

...and pretty much all interesting real world physics are non-linear functions.

So gravity for instance - if acceleration = time*gravity and position = time*acceleration, the relationship between position and gravity over time is nonlinear, specifically it changes with the square of time elapsed (position = time*time*gravity). Doing that calculation as the sum of repeated linear calculations, will have error. The magnitude of that error will change with your time-step size.

The way that's a problem with a game, is when a level is dsigned so that gap is exactly the right distance to be able to jump across it - but then some slower computer uses a different larger time-step than your level designer - so on that fast computer, you can't make the jump, cause the error on the gravity effect is higher, so it pulls the player down sooner.

Some other examples of non-linear places with error are springs, friction, application of the force of explosions that aren't instantaneous, etc. etc. All those things and more will behave differently based on your time-step.