average velocity, as3
Posted
by VideoDnd
on Stack Overflow
See other posts from Stack Overflow
or by VideoDnd
Published on 2010-06-02T17:06:18Z
Indexed on
2010/06/03
9:54 UTC
Read the original article
Hit count: 346
flash
|actionscript-3
Hello,
I need something accurate I can plug equations in to if you can help. How would you apply the equation bellow?
Thanks guys.
AVERAGE VELOCITY AND DISPLACEMENT
average velocity
V=X/T
displacement
x=v*T
example
I have 30 seconds and a field that is 170 yards. What average velocity would I need my horse to travel at to reach the end of the field in 30 seconds. I moved the decimal places around and got this.
Here's what I tried 'the return value is close, but not close enough'
FLA here
var TIMER:int = 10;
var T:int = 0;
var V:int = 5.6;
var X:int = 0;
var Xf:int = 17000/10*2;
var timer:Timer = new Timer(TIMER,Xf);
timer.addEventListener(TimerEvent.TIMER, incrementCounter);
timer.start();
function formatCount(i:int):String {
var fraction:int = Math.abs(i % 100);
var whole:int = Math.abs(i / 100);
return ("0000000" + whole).substr(-7, 7) + "." + (fraction < 10 ? "0" + fraction : fraction);
}
function incrementCounter(event:TimerEvent) {
T++;
X = Math.abs(V*T);
text.text = formatCount(X);
}
tests
TARGET
5.6yards * 30seconds = 168yards
INTEGERS
135.00 in 30 seconds
MATH.ROUND
135.00 in 30 seconds
NUMBERS
140.00 in 30 seconds
control timer 'I tested with this and the clock on my desk'
var timetest:Timer = new Timer(1000,30);
var Dplus:int = 17000;
timetest.addEventListener(TimerEvent.TIMER, cow);
timetest.start();
function cow(evt:TimerEvent):void {
tx.text = String("30 SECONDS: " + timetest.currentCount);
if(timetest.currentCount> Dplus){
timetest.stop();
}
}
//far as I got...couldn't get delta to work...
T = (V*timer.currentCount);
X += Math.round(T);
© Stack Overflow or respective owner