# Time lapsed acceleration & movement?

This topic is 4971 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Ok So I have taken may acceleration movement from:
Player.speed *= 1.002f ;


to:
// timeElapsed frame to frame
g_timeElapsed  = (float)(g_dCurTime - g_dLastTime);

//////
Player.speed *= (200 * g_timeElapsed) ;


The problem is that the player will not always move when i tell him to go.. its like the timeElapsed is to low to accelerate him... I feel that i am missing something here.. :::;P >

##### Share on other sites
What if Player.Speed = 0? You can multiply 0 by all you want, it is still 0.

The correct equation for velocity would be:

new velocity = old velocity + time elapsed * acceleration

##### Share on other sites
MTClip,

Acceleration is defined in physics as the change in velocity over time. The exact mathematical definition is:

(v1 - v0) = at

This is read as Velocity at time 1, minus velocity at time 0, is equal to the product of acceleration and the elapsed time.

But you already know the values of v0, a, and t. So what you're trying to find, I believe, is the new velocity. So taking the above equation and solving for v1 you get.

v1 = at + v0.

So, if you multiply your acceleration by the elapsed time, and then add to it the starting velocity, you'll get your velocity after acceleration.

It appears as though your equation for elapsed time is correct, so you need only plugin in your acceleration and previous velocity and you should be fine.

Your code then should look something like

// Assuming 200 is your accelerationPlayer.speed = ( 200 * g_timeElapsed ) + Player.speed;

Cheers and good luck!!

##### Share on other sites
okay yeah... that makes me retarded.... for some reason i just wasnt even thinking physics... thanks guys..

##### Share on other sites
You must also control your FPS before applying any movement. If your code is run on any other machine, then it is going to alter your gameplay. Try fixing your FPS and then apply the movement. This will help you to control your movement accurately.

• ### What is your GameDev Story?

In 2019 we are celebrating 20 years of GameDev.net! Share your GameDev Story with us.

• 15
• 9
• 11
• 9
• 9
• ### Forum Statistics

• Total Topics
634134
• Total Posts
3015751
×