Jump to content
  • Advertisement
Sign in to follow this  
MTclip

Time lapsed acceleration & movement?

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

If you intended to correct an error in the post then please contact us.

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 this post


Link to post
Share on other sites
Advertisement
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 this post


Link to post
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 acceleration
Player.speed = ( 200 * g_timeElapsed ) + Player.speed;


Cheers and good luck!!

Share this post


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

Share this post


Link to post
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.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!