- Home /
if(transform.rotation >= Quaternion.Euler(0, 0, -1f)) Error,If Quaternion >= Quaternion how come this doesn't work
Why can't I use the greater than or less than here and how can I fix it.
,My Script -
if(transform.rotation >= Quaternion.Euler(0, 0, -1f)) { FacingRight = true;
} else {
FacingRight = false;
}
The error is that you cant use >= or <= when using Quaternion So how can I fix that
Answer by Captain_Pineapple · Jun 20, 2018 at 10:36 PM
Hey there,
a quaternion is a 4-D Vector. It is kind of difficult to use a greater/smaller than operation on any kind of vector.
So assuming that you want to check if - let's say your player object - is facing left or right you could choose from some methods but that all depends on your exact setup. For example you could check for the euler angles that you get from your transform.rotation but this is kind of flawed if you do some more complex rotations.
Best would be if you specified a bit more information about your project.
The specifics is that when the gun is rotated to the left I want to activate facingright = false
but rotated relative to what? to your player object? to the world coordinate system?
And most importantly: Are we talking about 2d or 3d?
If you could describe more details or attach an explaining picture that might prove helpfull.
Answer by sgthale · Jun 20, 2018 at 10:58 PM
If you want to see if an object is aiming higher than something. You gotta use local direction vectors not Quaternions, not Euler angles. Reason is that if you use Euler angles, the pitch and roll can represent the same "up" direction. So if you use a local direction vector, you can just check how high the y component is. Then go from there.
Your answer
Follow this Question
Related Questions
How to fix flipping Euler anlges? 0 Answers
[SOLVED] Rotation/angled offset in Quaternion.Lerp for a carried GameObject 2 Answers
Clock script with custom time not working 0 Answers
Addition Quaternion 0 Answers
Rotation by Quaternion Slerp problems 0 Answers