I have a spaceship model I’m trying to pitch, roll and yaw using AddRelativeTorque. Pitching around the X axis works correctly but when it comes to adding yaw around the Y axis the model rotates around the Z axis and the Y axis. The same happens when I try to roll about the Z axis.
I have set the center of mass to (0,0,0) hoping this might solve it but it makes no difference.
Is this likely to be something to do with my model or my code (see below)?
var centreofmass : Vector3;
function FixedUpdate () {
rigidbody.centerOfMass = centreofmass;
//Upward Thrust
if(Input.GetKey("up")){
rigidbody.AddRelativeForce(Vector3(0,upThrust,0));
}
//Downward Thrust
if(Input.GetKey("down")){
rigidbody.AddRelativeForce(Vector3(0,downThrust,0));
}
//Left Thrust
if(Input.GetKey("left")){
rigidbody.AddRelativeForce(Vector3(-upThrust,0,0));
}
//Right Thrust
if(Input.GetKey("right")){
rigidbody.AddRelativeForce(Vector3(upThrust,0,0));
}
//fwd Thrust
if(Input.GetKey("left shift")){
rigidbody.AddRelativeForce(Vector3(0,0,fwdThrust));
burnFuel();
}
//bckwrd Thrust
if(Input.GetKey("left ctrl")){
rigidbody.AddRelativeForce(Vector3(0,0,downThrust));
}
//Turn Left
if(Input.GetKey("a")){
rigidbody.AddRelativeTorque(Vector3(0,-rotateSpeed,0));
}
//Turn Right
if(Input.GetKey("d")){
rigidbody.AddRelativeTorque(Vector3(0,rotateSpeed,0));
}
//Pitch Up
if(Input.GetKey("s")){
rigidbody.AddRelativeTorque(Vector3(-pitchSpeed,0,0));
}
//Pitch Down
if(Input.GetKey("w")){
rigidbody.AddRelativeTorque(Vector3(pitchSpeed,0,0));
}
//Roll Left
if(Input.GetKey("q")){
rigidbody.AddRelativeTorque(Vector3(0,0,pitchSpeed));
}
//Roll Right
if(Input.GetKey("e")){
rigidbody.AddRelativeTorque(Vector3(0,0,-pitchSpeed));
}
}