Hey,
I am stuck trying to rotate an object around the X axis. I have tried numerous approaches but I have not been able to rotate the object past 90 and 270 angle. I have converted all my code to quaternions but whatever I do, I cannot get it to work.
This is my current code, I would appreciate it if someone could point out where I am going wrong. Thanks
void Update ()
{
//get inputs
pitch = Input.GetAxis("Pitch") * (Time.deltaTime * pitchSpeed);
yaw = Input.GetAxis("Yaw") * (Time.deltaTime * yawSpeed);
roll = Input.GetAxis("Roll") * .5f;
//implement throttle
thrust += Input.GetAxis("Throtle") * (Time.deltaTime * throtleSpeed);
thrust = Mathf.Clamp(thrust, 10000, 60000);
//smoothen rotaions
smoothPitch = Mathf.LerpAngle(smoothPitch, pitch, Time.deltaTime * pitchSmoothness);
smoothYaw = Mathf.LerpAngle(smoothYaw, yaw, Time.deltaTime * yawSmoothness);
smoothRoll = Mathf.LerpAngle(smoothRoll, roll , Time.deltaTime * yTurnSmoothness);
//gameobject rotation
myTransform.rotation *= Quaternion.Euler(-smoothPitch, smoothRoll + smoothYaw, 0);
//Have also tried this-
//myTransform.Rotate(-smoothPitch, smoothRoll + smoothYaw, 0);
//add thrust
myRigidbody.velocity = myTransform.forward * (Time.deltaTime * thrust);
}
suggestion removed Check this link out : http://keithmaggio.wordpress.com/2011/07/01/unity-3d-code-snippet-flight-script/
– AlucardJayThat won't help - you're still converting it to the Euler representation, which is what causes Gimbal Lock.
– Hoeloe