- Home /
Euler Angle problem in If check
I am rotating my object by 90 degree over some time according to the following code.
thisTransform.RotateAround (thisTransform.position, degrees, 90*Time.deltaTime);
What I want to do is when the rotation of the object is (0,0,0), I want to do something (disable the script in the check). I print the euler angle in console and it shows (0,0,0). So according to the print value my if check must work.
euler = transform.eulerAngles; if(euler == Vector3(0.0,0.0,0.0) { //(perform something) }
Sometimes after performing rotation, the euler.x doesn't match the (0.0) check (I have divided my check to subchecks according to their x, y and z). When I saw in inspector against the "Rotation" values, the x value of the object is 1.001791e-05. At the same time the print statement shows it as 0.0 . I have attached the screenshot which shows my problem. As you can also see in console it misses the "XXXXXXXX" check because of the different value in inspector. Help me with the correct angle so I can perform my if check according to its (0,0,0) rotation. Thanks
see this question, or better it's first answer and the comment on it
I got it. then this is due to floating points. Is there a way I can convert these floating point to integer so I get the first part of the floating point excluding the part after the point. Something like this var integer : int = (int)floatingpoint; will this thing help me regarding my problem.
I have a confusion why the floating point is messing in this case (if that is whats happening). If I get the rotation of the current object it still gives me 0.0 while in inspector its 1.0000....
will try these two lines in the morning and will let you know if it works. Thanks anyways.
Thanks robertbu the following line helped me with my solution to what i was trying to do.
if (Quaternion.Angle(transform.rotation, Quaternion.identity) < some_small_value)
Answer by robertbu · Jul 15, 2013 at 09:15 PM
You can use Mathf.Round() to round a float to an int, but consider doing something like:
if (Quaternion.Angle(transform.rotation, Quaternion.identity) < some_small_value)
or
if (Vector3.Angle(transform.forward, Vector3.forward) < some_small_value)
Your answer
Follow this Question
Related Questions
Store initial rotation in JavaScript 2 Answers
Trouble Spawning Bullets with proper rotation 0 Answers
Object makes random jumps in rotation 1 Answer
How can I store the individual values of EulerAngles on a Database then re-apply 2 Answers
Trying to tween the rotation of a cube in x and z and having trouble 2 Answers