Hello. I have a little problem. I want to rotate my ship with the down arrow key, and with the up arrow key i want the ship to fly in the facing direction. My question is, how do i do the flying part. The rotating part is easy for me. You can explain me in AS2 or AS3, but i'm totaly stuck right there. Greets. PrideRage
The 'Point' class contains a static method called 'Polar'. You use it like this:
Point.polar(distance, angle) //returns a Point date type object
It's used to move a point by a specific distance and angle. So you can take the x and y value of your space ship, do a bunch of stuff, and you'll be able to move your ship by the specified angle and distance.
Mess around with the code, and maybe something magical will happen. I don't have enough experience to guide you step by step, so good luck
//Creates variable for distance parameter; doesn't have to be 100, //you can specify a different distance depending on what you prefer var distance:Number = 100;
//Creates another variable for angle parameter (in radians) //you can convert with: radians = degrees * Math.PI / 180 var angle:Number = (YourShip.rotation * Math.PI) / 180;
//Creates additional variable to use to move your ship var translatePoint:Point = Point.polar(distance, angle);
//Applies translation to your ship coordinates, for "flying" YourShip.x += translatePoint.x; YourShip.y += translatePoint.y;