- Home /
Detecting a certain degree angle?
Hey, trying to figure out how to detect if a rotation is greater than 180 degrees or less than, so I can change states.
I'm coding in C# and can't really find out how to say in code
if transform.rotation = <180
or something like that, no idea how to do it. Any help would be appreciated.
Answer by Berenger · Feb 16, 2012 at 10:28 PM
Rotation are done around an axis, so you need to access the good component. However, transform.rotation is a quaternion, which is a little complicated. But you can use the property eulerAngles. So, to test the rotation around the y axis :
if( transform.rotation.eulerAngles.y = <180 ) ...
Tested it, was giving me a parsing error and a unexpected symbol `<'
This seems like it would be fine, but the syntax is
if( transform.rotation.eulerAngles.y
Works like a charm guys, thanks heaps for the help, I really appreciate it.
Hmm, seems that the code works fine, but now working how I can lock to just between 2 angles, for example (Between 300 - 210 degrees) ins$$anonymous$$d of it just being greater than or less than
Answer by mpavlinsky · Feb 16, 2012 at 10:30 PM
What are you using it for exactly? Do you want to know if something rotated 180 degrees in any combination of directions? About a single axis? Is the rotation relative to another object, like trying to detect if something is facing opposite to something else?
Well, in the end, what I'm wanting to do is make a "dive" state when the player's mount is free falling through the air, once his rotation along the X is between 330 and 210, he'll change to the dive state.