- Home /
Euler Angles question
I want my object to straighten out after rotating on the z-axis. Here is my script - it doesn't seem to do anything. What is wrong with it? function Update (){
var rotationz = transform.eulerAngles.z;
if ((rotationz > 5) && (rotationz < 180)){
transform.Rotate (0,0,-30*Time.deltaTime);
}
if ((rotationz > -5) && (rotationz < -180)){
transform.Rotate (0,0,30*Time.deltaTime);
}
}
Thanks.
Answer by Antony-Blackett · May 14, 2011 at 01:41 PM
Your second if statement seems wrong if you want it to be the same as the first if statement but with negative values. I'd assume you mean to write this instead.
function Update (){
var rotationz = transform.eulerAngles.z;
if ((rotationz > 5) && (rotationz < 180)){
transform.Rotate (0,0,-30*Time.deltaTime);
}
if ((rotationz < -5) && (rotationz > -180)){
transform.Rotate (0,0,30*Time.deltaTime);
}
}
Notice that when testing against negatives the greater than and less than signs are flipped.
Well, it didn't work entirely, but I've thought of a new idea. Thanks though.
Your answer
Follow this Question
Related Questions
Continuously rotating by 90 doesn't get me the initial angle 0 Answers
Rotation losing precision 0 Answers
Whats the Difference Between Rotation EulerAngles and Quaternions? 2 Answers
How can I store the individual values of EulerAngles on a Database then re-apply 2 Answers
How to get inspector rotation values ? 2 Answers