Home Contents Forum Links Tip Jar
Animation Math in Lingo       

Friction

Friction occurs when materials are in contact with each other but have different velocities. This demo deals with air friction, which is a useful one in animation. An object moving through air experiences friction with the air, which pushes against the object.

To "model" a force such as air friction, the first questions to ask are what direction does it act in, and what determines its strength?

Unlike surface gravity in the last demo, whose direction is always downward, air friction always pushes in the direction opposite the object's velocity. And its force increases as velocity increases.

How can this be expressed in terms of the variables in the physics model? Since the direction and force of air friction depend on velocity, the formula will be relying on xVelo and yVelo. It's form is friction = -velocity.

  property sp

--position, velocity, acceleration
property x, xVelo, xAccel
property y, yVelo, yAccel

--forces
property xGrav, yGrav
property xFric, yFric

on beginsprite(me)
  sp = sprite(me.spritenum)
  x = sp.loch --initialize position
  y = sp.locv 
  xVelo = 0   --start at rest
  yVelo = 0
  xGrav = 0
  yGrav = .4  --constant downward
end

on exitframe()
  --friction
  yFric = -yVelo * .06
  xFric = -xVelo * .06

  --acceleration is sum of forces
  xAccel = xGrav + xFric
  yAccel = yGrav + yFric

  --increment velocity and position
  xVelo = xVelo + xAccel
  yVelo = yVelo + yAccel
  x = x + xVelo
  y = y + yVelo

  --set sprite position
  sp.loch = x
  sp.locv = y
end

Air friction - source movie   - To restart, right-click and select "restart"

Due to air friction, the motion is similar to a feather or a snowflake. The object cannot exceed its terminal velocity, which is the velocity at which the force of friction pushing up equals the force of gravity pulling down. At terminal velocity, what does the expression yGrav + yFric equal?

Since there is no horizontal motion, all the "x" statements could be removed without affecting the program. However, this script shows the general form of the two-dimensional physics model. And now its easy to add a little horizontal motion, by either setting the initial horizontal velocity or gravity's horizontal component (funky gravity, try it!).

Why multiply velocity by .06 to get friction? It scales the friction down in relation to velocity, and was a matter of testing values until the animation looked like I wanted. The .06 could be considered the viscosity of the air—the greater you make it, the more it looks like the object is moving through molasses. The expression for the basic idea behind a force, like
friction = -velocity, is usually then scaled so that its effect is proportionally correct in relation to other elements of the animation.

The type of behavior that air friction causes is useful in animation, because it is a general way of limiting the velocity of an accelerating object, even though you may not be trying to imitate an object moving through air.

Sliding Friction
Another common type of friction is sliding friction, where one object slides on a surface. This friction still resists an object's motion, but it acts differently depending on whether the object is stationary or moving, called "static friction" and "kinetic friction". A demo might be made later, but for now I'll just describe what happens briefly.

As you begin to push on a stationary object, it doesn't move. Static friction increases to oppose the force of your push, until you push hard enough and the object begins to move. At this point the friction between the object and the surface lessens and is called kinetic friction. Kinetic friction is constant regardless of velocity.

What is sliding friction good for in animation, other than animating a sliding object? It doesn't seem to be as useful as air friction. You might use the idea of the static friction part to make an object look like it was "stuck" until it was pushed on hard enough.

 
 


Copyright © 2003 JM Harward 
 jmckell~at~jmckell~dot~com
All lingo provided on this site may be used freely for educational purposes. Not for redistribution as uncompiled code. Instructional materials may not be reproduced without permission.