Home Contents Forum Links Tip Jar
Animation Math in Lingo       

Two Axes

Movement on two axes - source movie -  To restart, right-click and select "restart"

property sp
property xVelocity, yVelocity

on beginsprite(me)
  sp = sprite(me.spritenum)

  --initialize velocity x & y
  xVelocity = 5
  yVelocity = 1
end

on exitframe()
  --increment position
  sp.loch = sp.loch + xVelocity
  sp.locv = sp.locv + yVelocity
end

This script is the same as the last, but now there is vertical velocity as well as horizontal. Moving an object both horizontally and vertically produces a diagonal motion.

The variable for vertical velocity starts with y to indicate it is used for velocity along the y axis, while xVelocity is the velocity along the horizontal x axis.

These two parts are the vertical and horizontal components of the motion. The vertical component is 1 px down, and the horizontal component is 5 px to the right.

•If vertical velocity is set to zero, how does it compare with the one-axis example?

With two axes to work with, you can make the object move in any direction on the two-dimensional screen (try it!).

So what is the definition of velocity? It is the change in position over time.

 
 


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.