Sign in to follow this  

friction-calculation?

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

Hi I simply do this for my vehicles: //friction for(int ii=0;ii<ooo.gameSpeed;ii++){ speed.x*=NATURAL_FRICTION; speed.y*=NATURAL_FRICTION; } Fine. But as FPS drops friction becomes less as my deltaTime is not included in this friction-calculation. But i cannot simply multiply it in there like i do when calculating movement. I need to keep it fast also since this is used A LOT in my game. I understand i can do a loop and apply the friction many times depending on the size of deltaTime, but this will eat a lot of CPU in the long run. Any smart math-function for this? Thanks E

Share this post


Link to post
Share on other sites
The "correct" solution is


speed.x *= pow(NATURAL_FRICTION, dt);



where dt is the elapsed time, and NATURAL_FRITION is the fraction of speed that is left after an interval of dt=1.

For example, if dt is measured in seconds, and you want your speed to decay by 25% in one second, then use pow(0.75, dt).

Note though, that pow() is quite an expensive operation. For this and various other reasons, you may well be better off using a fixed timestep.

Share this post


Link to post
Share on other sites
Quote:
Original post by suliman
yeah i could just cap the fps to a fixed value most computers should be able to handle and calculate a fixed friction value from that...

Can that pow use decimals? What if dt is 0.002?


Yep, fractions are fine.

Share this post


Link to post
Share on other sites

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