PDA

View Full Version : parabola problem



OMG
January 11th, 2009, 10:11 PM
Hi again, I've been inactive for over 2 years (I've been very busy, I program for fun), and just now I needed to test something in flash and like I thought I screwed up, plz help >_<

this is an engine that makes the ball move in a curved line. On paper with small x and y values it looks ok but when it's on flash (500 x 400) the curve looks ridiculous >.>


//ball's initial positions
var initX:Number=30;
var initY:Number=350;
//initial x + goX = final x position, the motion stops when reached
//initial y + goY = highest point
var goX:Number=200;
var goY:Number=100;
//some numbers I need to know to find the equation of the parabola
var h:Number;
var k:Number;
var a:Number;
//y=a(x-h)^2+k
//see next comment
function doParabola(distX:Number, distY:Number):void {
h=initX+distX/2;
k=initY-distY;
//a=(y-k)/(x-h)^2
a=((initY-k)/(initX-h)*(initX-h));
}
doParabola(200, 70);
addEventListener(Event.ENTER_FRAME,moveBall);
function moveBall(e:Event):void {
ball1.x++;
ball1.y=a*(ball1.x-h)*(ball1.x-h)+k;

trace(ball1.x,ball1.y);
//stops the ball
if (ball1.x>=initX+goX) {
trace("stop");
removeEventListener(Event.ENTER_FRAME,moveBall);
}
}
//
var ball1:ball=new ball();
addChild(ball1);
ball1.x=initX;
ball1.y=initY;

(ROFL I guessed the tags for actionscript code)

isn't the ball supposed to move 200 pixels in length and 70 in height...sry I suck at math x.x
(I think the problem has something to do with flash's inversed y)

neilmmm
January 12th, 2009, 12:14 PM
curved movement is simpler than that

you move the mc on _y and _x

if you want to go up and then down you keep decreasing the amount you are taking away from the y axis until it becomes and a negative - and starts adding


var xmov:Number=12;
var ymov:Number=6;
var gravity:Number=0.4;
ball_mc.onEnterFrame=function () {
this._x+=xmov;
this._y-=ymov;
ymov-=gravity;
}

make a small circle name it ball_mc and put it in the bottom left of your stage

OMG
January 12th, 2009, 06:33 PM
that works, but the problem is that I can't control the maximum height and length of the parabola with that method...