Jump to content
  • Advertisement
Sign in to follow this  

Apply friction over time

This topic is 2329 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

Im working on a 2D fighting/platformer game. As it is now it works fine, I handle movement by adding vectors to a Velocity vector.

[source lang="csharp"]Velocity += v;[/source]

Then at the end of each frame, where elapsedTime is the time elapsed since previous frame.

[source lang="csharp"]Velocity += gravity; //Apply gravity
Position += Velocity * elapsedTime; //Move the object
Velocity *= 0.8f; //Friction[/source]

Now to the problem: My above functionallity only works accurate if the game is running at 60 fps since the friction multiplication is not time varying, but a constant.

Ive tried where I divide the elapsedTime by the target fps.
[source lang="csharp"]Velocity *= 0.8f/0.016f * elapsedTime;[/source]

I think I have to use Math.Pow() for this to work, but I cant get my head around it. Edited by Doggolainen

Share this post

Link to post
Share on other sites
you just have to use friction^timeDelta

edit: however, it would be probably more efficient to do physics with a fixed time step Edited by Inferiarum

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!