- Home /
check rotation?
Is there any way check the rotation of an object for a condition? So you could have something like if (the objects rotation == (0,90,0)){something}? Thanks
Answer by Jesse Anders · Mar 22, 2011 at 11:02 PM
You can certainly write something like:
if (transform.eulerAngles == new Vector3(0f, 90f, 0f)) {...}
However, there are two problems with this approach. The first is that due to floating point error, the above equality is unlikely ever to evaluate to 'true' (under normal circumstances, at least). The second problem is Euler-angle aliasing, which, although it might not be a problem in the specific examples above, does make direct comparison of orientations in Euler-angle form somewhat inadvisable in the general case.
There are various ways you can determine how 'close' one orientation is to another though. If you're only concerned with yaw (as your example suggests), you could use simple vector math to see if the object is more or less 'pointing in the right direction'. In the more general case, you can use the quaternion dot product for this. (Keep in mind though that q and -q represent the same orientation, which needs to be taken into account when performing the dot-product test.)
Your answer
Follow this Question
Related Questions
Flip over an object (smooth transition) 3 Answers
Rotating projectile 2 Answers
transform position y changes when character rotates 0 Answers
eliminating angular velocity when clamp value hit? 0 Answers
rotate on the Y axis 1 Answer