- Home /
i want an object rotate 45 degrees more than an other one
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
there is a huge intro to Quaternions, etc on unityGE$$anonymous$$S.com
Answer by Montraydavis · Oct 31, 2012 at 02:44 AM
I don't even see anywhere in your script where you specify rotating 45 degrees more than the first object. Also, which axis are you trying to rotate it by 45 degrees??
var Object1 : GameObject ;
var Object2 : GameObject ;
Object2.transform.Rotate ( Object1.transform.rotation.x + 45, Object1.transform.rotation.y + 45, Object1.transform.rotation.z + 45 ) ; // This rotates Object2 45 degrees more than Object 1 on axis XYZ .
But obviously, you will have to do a bit of work to make that smoothly rotate, but, that is the basis of what you "asked".