ForumsProgramming ForumRotation and Moving in this direction.

4 4614
PrideRage
offline
PrideRage
148 posts
Nomad

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

  • 4 Replies
BeastMode10
offline
BeastMode10
374 posts
Nomad

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

PrideRage
offline
PrideRage
148 posts
Nomad

Thx, helped me alot.

PrideRage
offline
PrideRage
148 posts
Nomad

Well i still need a bit of help there. Don't get it with the Polar.point

BeastMode10
offline
BeastMode10
374 posts
Nomad

I don't exactly understand the Polar method too well either, so bear with me here

/*
* AS3
*/

//imports necessary intrinsic classes
import flash.geom.*

//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;

Showing 1-4 of 4