Sign in to follow this  

Apply friction over time

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

This topic is 1987 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.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this