# 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.

## 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 on other sites
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 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 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 on other sites
Quote:
 Original post by sulimanyeah 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 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.

## Create an account

Register a new account

• ### Forum Statistics

• Total Topics
628645
• Total Posts
2984023

• 9
• 9
• 9
• 10
• 21