Home | AI | Physics | Mathematics | Compiler Design | Games | Downloads | About Me
You are visitor number 147052 since February 2003
Physics
Introduction
Velocity
Acceleration
Momentum
Collisions
Gravity
Friction
 
Free Books


Friction

When you were playing with the acceleration tutorial, you have noticed that the car stops after a while. The car stops because of friction (or drag as it is also known in the game world). Friction can be defined as the loss of energy due to heat or kinetic energy transfer. This is what happened in the acceleration tutorial whilst you were playing with the car. Whenever you pressed the up key (accelerated the car), the car's velocity kept building up until it reached stability. But whenever you r eleased the key, the car would stop moving after a while. This is equivalent to a real car when you press the gas pedal and release the gas pedal. The car stops moving because friction in the transmission (a well as the engine, bearings, etc…) and the environment (wind, the road's surface, and so on), decrease kinetic or &quo;motional&quo; energy.

The mathematical model for friction is a bit complicated and so I am not going to cover it here in this tutorial. You can find that in any good physics book. Here I am going to present you the formula to simulate friction in a video game or animation.

You can think of friction as an entity that makes the velocity of an object decrease over time. For instance, in the gravity tutorial I have described that by modelling gravity only, our object would bounce forever. Now, if we add friction (air resistance, etc…), the object will stop bouncing after a while. That is, its velocity will be equal to zero. This is easily done by decreasing some value from our velocity each game cycle. This is how we do it:

for each cycle
     vx = vx − friction ⁄⁄ we do not have gravity in x
     vy = vy − friction + gravity
     px = px + vx
     py = py + vy
     draw_object(px, py) ⁄⁄ draw the object

As an example, have a look at the flash movie below. Grab the ball and then drop it or throw it. You will see the ball bounce and then stop after a while.

That's all about friction. If you have any queries regarding friction, you may send me and email.

Best Regards

Fidel





Books



© 2002, 2003 Fidel Viegas. All rights reserved.