Factor Three
Factor Three

Reputation: 2284

Projectile Motion in Flash's Coordinate System

I am looking at a formula that is supposed to help calculate trajectories for projectile motion. The answer I am looking at is at the following URL:

Calculating Trajectory for Projectile Motion

The formula actually seems to work -- except that it is calculating the y- position based on the idea that the screen's coordinate system has the origin at the bottom- left corner. In Flash, the coordinate system is in the upper left corner, and the higher the y- position, the farther down it gets! This means that instead of arching up, then back down again, the projectile goes down, then up!

I need to find some way to translate my y- values so that a projectile can look like it is going up and down in a proper parabola. Does anyone have any idea how to do this?

Someone please advise...

Upvotes: 0

Views: 118

Answers (1)

mitim
mitim

Reputation: 3201

Looking at your link (sorry, should have looked at this first to see what method you were using to calculate your motion -I was presuming you were using something else), if you want it to go 'up' rather then 'down' you can just flip the sign on the second line of code in the event handler:

instead of:

cannonball.y = inity + Math.sin(angle) * initVelocity * Time - G * Time * Time * 0.5;

you can go (added brackets):

cannonball.y = inity - (Math.sin(angle) * initVelocity * Time - G * Time * Time * 0.5);

Reasoning is that the above is working by calculating the relative position of where the projectile should be, then adding it to the initial Y to get the final position. Adding makes it go 'downwards' as y += 1 would move an object down the stage. Since going the opposite y -= 1 would make it move up the stage, you can just subtract instead of add.

Upvotes: 1

Related Questions