The Trials and Tribulations of Tribology

Contents

Why Is it Such a Drag?

How's This Good For Games ?

How Do I Use This Knowledge ?

How Do I Use This Knowledge?

I am convinced. I want to have boxes that tip over if you push them too high. That seems like something cool to have in my game. But how do I go about accomplishing this task?

I have been building up the pieces I need. If you look back to my previous articles, "Collision Response: Bouncy, Trouncy, Fun," and "Lone Game Developer Battles Physics Simulator", I have a soft body dynamics package that models the forces and handles collision with surfaces. I will first handle the kinetic friction problem.

As I described above, the magnitude of the kinetic friction force is

and the direction of the force is determined by looking at the current particle velocity. In my simulation, if the velocity of a point is greater than a certain threshold, e, I determine that I need to use static friction for all contacting points. Listing 1 shows the code for calculating and adding in the force of friction.

The only change I really had to make to the structure of the program was to a storage space for the contact normal for contacting particles.

Static Friction

Handling static friction, however, is much more complicated. The problem is that static friction requires that I determine when each contacting particle makes the transition to sliding. From the calculations above, I know that the point of transition is when

F = µsN. Until that transition occurs, the static friction force needs to prevent sliding completely. That is, I need to make sure that the particle acceleration is kept at zero. Once the particle begins sliding, then the force opposes the acceleration and has a maximum of µsN. All of these conditions lead to a situation that is too complex to be calculated in my simulation. David Baraff (see For Further Info) suggests a couple of approximations.

The more complicated method Baraff suggests is to approach static friction as a quadratic programming problem. However, this method is prone to failure in certain circumstances. The other suggestion, fortunately, is easy to implement.

First, establish a velocity threshold value e which determines when to use static friction. This threshold is then used to scale the friction force as the velocity varies from 0 to this threshold. The formula for calculating the static friction force then becomes

F = (µsN)(v/e). This force is applied in the direction opposite the velocity of the particle. Listing 2 contains the code for handling the static friction forces.

A Word about Integration

In order for this static friction approximation to work, the particle must build up some velocity in order for the static force to kick in. If the value of e is too large, it can cause the object to crawl around a little. By reducing this value, the crawling effect can be eliminated.

One unfortunate side effect of this approximation of static friction is that it can play hell with your integrator. When the particle is moving and subject to kinetic friction, things work well. However, when static friction kicks in, the direction of the static friction force swings wildly with small fluctuations in velocity. This plays havoc with the integration. If the value for e is too small, the differential equations can become "stiff," requiring more complex integration techniques (See "Lone Game Developer Battles Physics Simulator").

Let's Drag

Now I can get objects to tumble around realistically as well as slow to a halt based on the current coefficients of friction. You can download the source code and executable to the sample application from the Game Developer web site (http://www.gdmag.com/).


When not fighting the friction that keeps his butt planted in Redondo Beach, Jeff creates custom 3D real-time graphics applications at Darwin 3D. What's the roughest surface you know? E-mail it to him at jeffl@darwin3d.com.

For Further Info

Baraff, David. "Coping with Friction for Non-Penetrating Rigid Body Simulation," Siggraph Proceedings: July 1991, pp. 31-40.

Beer and Johnston. Vector Mechanics for Engineers: Statics, Sixth Ed. New York: WCB/McGraw-Hill, 1997.

Hecker, Chris. "Behind the Screen" columns. Game Developer, October 1996-June 1997. Also available on Chris's web site at http://www.d6.com/.

Lötstedt, P. "Numerical Simulation of Time-Dependent Contact Friction Problems in Rigid Body Mechanics." SIAM Journal of Scientific Statistical Computing Vol. 5, No. 2 (June 1984):
pp. 370-393.

Discuss this article in Gamasutra's discussion forums.
Discuss this article in Jeff Lander's discussion forums.

________________________________________________________

Why Is it Such a Drag?