i am trying to make a spaceship controller. my idea was to use a cube make the spaceship move in the direction its aiming, and then the spaceship model to add details in this case, to tilt a bit while it is yawing. here is the code i`m using:
var forceCube : Transform;
var rotBufferZ = 0;
var rotBufferY = 0;
var rotBufferX = 0;
var maxRot : int = 1;
var roll = false;
var rollDir = 0;
var rollSpd = 1;
function Start () {
}
function Update () {
// this you`ll see why in a bit
if (Input.GetKeyDown(KeyCode.A))rollDir = -1;
else rollDir = 0;
if (Input.GetKeyDown(KeyCode.D))rollDir = 1;
else rollDir = 0;
//here i use it to change the maximum rotation angle from
//positive to negative based on in what rotation i want him
//to rotate
maxRot = maxRot * rollDir + forceCube.rotation;
// if it can roll hell do so
if (roll){
transform.Rotate(rollDir * rollSpd, 0, 0);
}
//check if he has gotten to the max rotation to make him
//stop rotating
if (transform.rotation >= maxRot)roll = false;
if (transform.rotation >= maxRot)roll = false;
}
i guess a local variable would also work but i don`t know how to use them
thanks to all ho tried to help