PDA

View Full Version : [MX] spaceship control - roation & thrust



Steveo
November 14th, 2004, 12:46 PM
hi

ive had a search of the tutorials and forums and am still stuck so...

im trying to create a basic spaceship flying game and the first problem ive got is controlling the ship. the controls i need are thrust and left-rotate and right-rotate. much like this,
http://www.kirupa.com/developer/mx/gamecontrols.htm
at the start this tut mentions 'game control tutorials' does anyone know where these are? i think i would find these useful. the above tut doesnt go into scripting.

at the moment to control rotation i have,

onClipEvent (enterFrame){
_rotation += 0;
}
on (keyPress "<right>") {
_rotation += 7;
}
on (keyPress "<left>") {
_rotation += -7;
}
but there is an initial pause in the rotation. can anyone suggest an alternative code.

thanks for any help

steveo

kode
November 14th, 2004, 04:40 PM
Rotate the object within the enterFrame event:

onClipEvent (enterFrame) {
var rotationdir = Key.isDown(39)-Key.isDown(37);
this._rotation += rotationdir*7;
}

Steveo
November 15th, 2004, 11:22 AM
thanks kode

rkalexander
November 15th, 2004, 01:17 PM
can u please explain what that means. i'm assuming you are creating a smooth rotation.

kode
November 15th, 2004, 03:27 PM
thanks kode
You're welcome. ;)

can u please explain what that means. i'm assuming you are creating a smooth rotation.
First off, you should know that boolean values are in fact numbers. true is equal to 1 and false is equal to 0.


The Key.isDown() method returns true is the specified key is being pressed and false otherwise. So, this is what happens when you press the right arrow and left arrow keys, which key code values are 37 and 39, respectively.

If you press the right arrow key:
var rotationdir = 1-0;
// (1 - 0 = 1) The variable is equal to 1
this._rotation += rotationdir*7;
// (1 * 7 = 7) Add 7 to the current rotation

If you press the left arrow key:
var rotationdir = 0-1;
// (0 - 1 = -1) The variable is equal to -1
this._rotation += rotationdir*7;
// (-1 * 7 = -7) Substract 7 to the current rotation

If you press both right and left arrow keys:
var rotationdir = 1-1;
// (1 - 1 = 0) The variable is equal to 0
this._rotation += rotationdir*7;
// (0 * 7 = 0) The rotation won't change