Skip to content

Determining Velocity

by Colin on May 20th, 2009

A few months ago I wanted to write down a little bit of code to remember how to determine velocity (because I knew I’d have to remember sooner or later. It’s really quite simple, you just need to compare 2 (or more values). Here’s one way you can do it…

Code to determine velocity:

var pX:int;
var pY:int;
var cX:int;
var cY:int;
 
stage.addEventListener (Event.ENTER_FRAME, getVelocity);
 
function getVelocity (e:Event) : void {
cX = -pX + (pX = stage.mouseX);
cY = -pY + (pY = stage.mouseY);
}

From → Flash

No comments yet

Leave a Reply

Note: XHTML is allowed. Your email address will never be published.

Subscribe to this comment feed via RSS