[SDL] object's speed control against different framerates
tommy.hinks at gmail.com
Sat Apr 28 04:11:57 PDT 2007
The thing to watch out for is if you have more complicated equations
to solve. In your case it seems to be x = v*dt. This equation is not
extremely sensitive for large timesteps, but other equations are. The
problem is then that if the framerate drops, the physics of the
simulation crash. Just something to be aware of. You might even notice
this effect if you add acceleration to the equations you have now.
One solution to this problem is to simply set a maximum allowed
timestep, but this means that the application is no longer produces
the same results for the same amount of frames.
On 27/04/07, Jeffrey Grembecki <tophatfox at gmail.com> wrote:
> On Fri, 27 Apr 2007 16:48:58 +0200
> C.Alvarez <blubzouf at gmail.com> wrote:
> > For time based movements, I use a basic pos = pos + speed * lastframetime
> > When I move an object with constant speed during constant time, one
> > second for example, I have no problem to end the movement at the same
> > position in any framerate.
> > When I tried to include variable speed movement, this seems to be a
> > little more complicated to interpolate the speed variation.
> > I have made this little code to explain what I mean, it just need to
> > press space to start the test, runs a desired movement, decreases the
> > speed, and automatically ends ( with log in stdout.txt ).
> Without looking at the code it sounds like a lack of precision. I've found the
> best method for timing is to use a fixed timer on the game loop, say 25 fps
> and within the render function do interpolation.
> This method while very good does add a little complication with the addition
> of prediction of events within the render function.
> The advantage is your game loop will always result in the same output no
> matter what frame rate you have and it is also possible to record player
> input for a replay.
> There's a good article on the subject at
> SDL mailing list
> SDL at lists.libsdl.org
More information about the SDL