Home Contents Forum Links Tip Jar
Animation Math in Lingo       

Physics Model
Position, Velocity, Acceleration, Force

A distinguishing characteristic of motion in the real world is that it is continuous. Objects don't jump instantaneously from point A to point B, nor do objects at rest start going 100 mph all of a sudden. Most animation attempts to give the impression of continuous motion, and using the ideas in physics is a good way to achieve that.

Acceleration
Velocity was introduced in the first two sections as the change in position over time. Acceleration has the same relationship to velocity as velocity has to position. It is the change in velocity over time.

What this means in terms of the variables in a program is that velocity is added to the object's position at each animation step, and also that acceleration is added to the velocity at each step.

Stepping on the gas - source movie - To restart, right-click and select "restart"

property sp
property x, xVelo, xAccel --position, velocity, acceleration

on beginsprite(me)
  sp = sprite(me.spritenum)
  x = sp.loch  --initialized to object's position
  
xVelo = 0    --zero, object starts at rest
  xAccel =
.1  --object will accelerate to the right
end

on exitframe()
  xVelo = xVelo + xAccel  --increment velocity
  x = x + xVelo           --increment position
  sp.loch = x             --set sprite position
end

You'll see the object flash by the screen again because Director "wraps" the location properties somewhere around 32000.

•What if the acceleration is -.2? What if the acceleration is -.2 and velocity is initialized to 10? Try it!

The two-axes demo showed how diagonal velocity was separated into vertical and horizontal components. This concept applies to acceleration as well. If you want an object to accelerate in a diagonal direction, express it as vertical and horizontal components. Try adding a vertical velocity and acceleration to the example above and see what happens.

With position, velocity, and acceleration you have the basic model for continuous motion. Its general form in programming:

xVelo = xVelo + xAccel
yVelo = yVelo + yAccel
x = x + xVelo
y = y + yVelo

(where x and y represent position)

Forces
In the real world, acceleration of an object is caused by a force acting on the object. Examples of forces are gravity and friction.

In animation, acceleration can be created without a force, as it was above by just setting the x-axis acceleration to .2. However, understanding various forces will give you more ideas to work with when trying to get a particular motion you want.

 
 


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.