Spaceship Flight

I am currently trying to make a simple space type scroller game and i am currently working on making the spaceship fly :slight_smile:
I have opened up the thrust space sample and copied the code from there and edited bits :), however would like the spaceship to fly up and down more like the way it flys right (forwards)

This is the code i have so far
I am really struggling with making the spaceship strafe up and down the same way it flys forward. whenthe spaceship flies up or down i don’t want it to rotate :slight_smile:

I have tried copying and pasting the code for the right movement to the up and down bits and altering it however i can’t get it to fly up or down

[edit] I would also like to make it so that when the key left is press the spaceship slows down steadily to a stop. (not stop suddenly or stop too slow like it would otherwise)

Please could someone help me :slight_smile:


[color=green][color=#000000][color=green]onClipEvent (load) {
// declare and set initial variables
thrust = 0.1;
decay = .98;
maxSpeed = 25;
}[/color]
[color=red]onClipEvent (enterFrame) {
// rotate right or left
if (Key.isDown(Key.UP)) {
_y -= 10;
}
if (Key.isDown(Key.DOWN)) {
_y += 10;
}
//[/color] 
[/color][color=green]// 
if (Key.isDown(Key.RIGHT)) {
// calculate speed and trajectory based on rotation
xSpeed += thrust*Math.sin(_rotation*(Math.PI/180));
ySpeed += thrust*Math.cos(_rotation*(Math.PI/180));
flames._visible = 1;
} else {
// deccelerate when Up Arrow key is released
xSpeed *= decay;
ySpeed *= decay;
flames._visible = 0;
}
// 
// maintain speed limit
speed = Math.sqrt((xSpeed*xSpeed)+(ySpeed*ySpeed));
if (speed>maxSpeed) {
xSpeed *= maxSpeed/speed;
ySpeed *= maxSpeed/speed;
}
// 
// move spaceship based on calculations above
_y -= ySpeed;
_x += xSpeed;
// 
// loop to opposite side of the stage when the spaceship travels off-screen
if (_y<0) {
_y = 300;
}
if (_y>300) {
_y = 0;
}
if (_x<0) {
_x = 600;
}
if (_x>600) {
_x = 0;
}
}[/color]
[/color]

Thank you :slight_smile:
I hope you understand what i meant
The bits in red are the up and down movement which i would like to be more like the thrust movement