I’ve got a Game Object, that ist, basically a big ring. The Game Object itself rotates continouusly negative around it’s x-axis, and I have to know, where it is currently.
At least, the Object is normally, without the x-Rotation, not rotated in any way…
Around the Object are 40 “Sections” and a My script has to know wich of these Sections is at top.
So I use the rotation.eulerAngles.x value and diviedy it by 9. With Math.RoundToInt I finally get the Section that is at top. Works all very fine, but it never gets to values from 270° over 180° to 90°. The ring rotates as it has to, but at 270° the x-Value instead of going on to 180° starts growing again to 360°, then counting upwards to 90° and there it turns back again and so on and so on… so my Problem now is that I get the “upper” Sections all twice like a Ping-Pong-Animation, and never the “lower” sections.
I know where the actual problem is: at x270° the y and z values flip from 0° to 180°, and at x90° the flip back to 0.
How can I get the real active Section now?
Oh and: Here Is my code:
var CurrentSection : int;
function Update ()
{
Debug.Log(transform.rotation.eulerAngles);
CurrentSection = Mathf.RoundToInt(transform.rotation.eulerAngles.x / 9.0);//Here I calculate the active Section
if(CurrentSection == 40)
{
CurrentSection = 0;//Section 40 is the same as Section 0, So I save them as the same value...
}
}