I have no idea what is wrong with this. Honestly. The _y of Bush goes above _root._height and still it does not stop animating. It starts out initially at a height that comes from god knows where. This was supposed to be easy
var simulate:Boolean = false;
var initialheight:Number;
var currentheight:Number;
var angle:Number;
var initialvelocity:Number;
var currentxvelocity:Number;
var currentyvelocity:Number;
var initialxvelocity:Number;
var initialyvelocity:Number;
var currenttime:Number;
var currentframe:Number = 0;
var framerate:Number = 30;
var g:Number = 9.81;
simulate_btn.onRelease = function() {
if (velocityinput.text != 0) {
initialvelocity = velocityinput.text;
angle = stepper.value;
initialheight = initialheightinput.text;
initialheight = _root._height - initialheight;
bush_mc._y = initialheight;
currentxvelocity = Math.cos(angle) * initialvelocity;
currentyvelocity = Math.sin(angle) * initialvelocity;
initialxvelocity = Math.cos(angle) * initialvelocity;
initialyvelocity = Math.sin(angle) * initialvelocity;
simulate = true;
}
}
onEnterFrame = function() {
if (simulate == true) {
currentframe++;
currentvelocitytext = currentxvelocity / Math.cos(angle);
currenttime = currentframe / framerate;
if (bush_mc._y < _root._height) {
bush_mc._y = _root._height - (initialheight + initialyvelocity*currenttime + (.5 * (-1 * g) * (currenttime * currenttime)));
bush_mc._x = currenttime * currentxvelocity;
}
}
}
FLA: