• 13
• 16
• 27
• 9
• 9

# Maximum speed via friction, drag, or what?

This topic is 2683 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Hey all. Up until recently I assumed that introducing friction into my code would mean that my critters would have a maximum speed. Thanks to this forum, and my own experiments, I of course realised that is not the case.

So despite a working implementation of friction, my critters can still accelerate indefinately. I need a way to stop that from happening.

What's the best technique to use in this case? Naturally the simpleset solution is just to clamp the velocity to some maximum value. I was just wondering if there is a more elegant, physically based, method that simulations use to limit the maximum speed of objects?

##### Share on other sites
Quote:
 Original post by dangerdaveCSHey all. Up until recently I assumed that introducing friction into my code would mean that my critters would have a maximum speed. Thanks to this forum, and my own experiments, I of course realised that is not the case.
What types of friction have you implemented? IIRC, it is indeed friction that prevents cars/humans from continually increasing speed, but you need to take into account multiple types of friction: static, sliding, rolling and drag (air-resistance).

##### Share on other sites
As long as your drag force (friction, air, made-up-force, whatever) increases exponentially with speed there will always be a point where the force required to overcome the drag equals the the force exerted by drag. This is terminal velocity :)

You probably need to make your friction exponential (proportional to velocity squared for instance). This will also have the effect of making them accelerate slower the faster they go which may or may not be what you are looking for. If not I'd fake it and have a maximum speed which you clamp to!

##### Share on other sites
I've implemented kinetic friction using the equation:

$\mathbf{v}_\perp = \mathbf{v} - \mathbf{n}(\mathbf{n}\bullet\mathbf{v})$

$F_{friction} = \mu\,(\mathbf{n}\bullet\mathbf{F})\,\frac{\mathbf{v}_\perp}{|\mathbf{v}_\perp|}$

Where: m is the friction coefficient; n is surface normal; F is total force (mostly just gravity); and v is velocity.

So its just a force in the opposite direction to the component of velocity planar to the surface, with a magnitude relative to the downward force.

This doesn't prevent an object accelerating indefinately, so I need some additional drag or something. I'm just wondering what's the best way?

EDIT: ah OK, thanks Noggs, make friction relative to square of velocity, intruiging. Should I modify my friction equation above to incorperate that? Or use a different function?

##### Share on other sites
Quote:
 Original post by dangerdaveCSEDIT: ah OK, thanks Noggs, make friction relative to square of velocity, intruiging. Should I modify my friction equation above to incorperate that? Or use a different function?
It depends whether you are going for what looks good, or attempting to simulate reality. If the former, I would just tweak your existing friction function to be quadratic, and play around with the factors till it looks right.

If the latter, there is a old GameDev article with the relevant formulas for quadratic air resistance (which may be worth looking at regardless).