Is this the right way, or at least a way that works, for dealing with accelerations in variable time steps evironments?
// Pseudo-code
void onUpdate() {
mySpeed += acceleration * timeElapsed; // More specifically, this part
myPosition += mySpeed * timeElapsed;
}
Truth to be said, I'm using a constant timeElapsed defined by (1.0f / FPS_LIMIT)
, FPS_LIMIT
being the value of the framerate at which I want the game to be locked. Speeds and accelerations are defined in the following ways:
#define FRAME_DURATION (1.0f / FPS_LIMIT)
#define RUNNING_SPEED 42 * FRAME_DURATION
#define GRAVITY 42 * FRAME_DURATION
And I have noticed that, the further I increase my FPS_LIMIT
, the faster things accelerate. Well, it's obvious (or not) that I'm using flawed logic to define the acceleration constants, but I'd also like to know what then I'm doing wrong and what'd be the right way to calculate these values, because what I'll pretty much be doing through my scripts will be as simple as this:
void onUpdate() {
mySpeed += acceleration;
myPosition += mySpeed;
}
As if framerate-independence didn't even exist.
If you want to get technical, I'm using simple SFML for the fixed time steps, through a window.setFramerateLimit(FPS_LIMIT)
call.