Sign in to follow this  
dangerdaveCS

Maximum speed via friction, drag, or what?

Recommended Posts

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

Any advice much appreciated.

Share this post


Link to post
Share on other sites
swiftcoder    18426
Quote:
Original post by dangerdaveCS
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.
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 this post


Link to post
Share on other sites
Noggs    141
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 this post


Link to post
Share on other sites
dangerdaveCS    122
I've implemented kinetic friction using the equation:





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 this post


Link to post
Share on other sites
swiftcoder    18426
Quote:
Original post by dangerdaveCS
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?
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).

Share this post


Link to post
Share on other sites
no such user    280
You don't even need quadratic drag forces to have a terminal velocity. As long as the applied force has a maximum value any resistive force that monotonically increases relative to velocity will create a terminal velocity. The curve shape of the resistive force will determine how quickly you reach terminal velocity. Linear drag forces are quite common when simulating things like parachutes or other aerodynamically unfriendly objects. Quadratic air resistance tends to be used for aerodynamic objects. (I know this sounds like a contradiction, but things with poor aerodynamics rarely reach a high enough speed that the quadratic terms of air resistance apply.)

Share this post


Link to post
Share on other sites

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