Public Group

# friction-calculation?

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

1. 1
2. 2
3. 3
Rutin
24
4. 4
5. 5
khawk
14

• 11
• 11
• 23
• 10
• 9
• ### Forum Statistics

• Total Topics
633651
• Total Posts
3013128
×