Jump to content
  • Advertisement
Sign in to follow this  
suliman

friction-calculation?

This topic is 4008 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
Advertisement
i know but dealing with forces makes turning, sliding and everything else much more complicated and i dont want that.

Given that i use friction like i do, is there any good way to handle the problem i presented in my first post?

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
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?

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
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!