- Home /
 
               Question by 
               baleadapp · May 07, 2020 at 09:33 AM · 
                rotationeuleranglesanglesz-axis  
              
 
              Continuously rotating by 90 doesn't get me the initial angle
I have a game object rotating 90 degrees every tow seconds, making the object to have 4 possible values for its Z rotation. Since the initial Z rotation is 45, the other values would be 135, 225, and 315. Every time the game object rotates, it looks for its current Z rotation in a Dictionary: 
 static public Dictionary<int, string> rotDirection = new Dictionary<int, string>{
         {45, "NE"},
         {135, "SE"},
         {225, "SW"},
         {315, "NW"},
     };
How ever, it's not finding the initial value (45) since what it gets in the rotation is actually 44. Why is this happening?
 float timer;
     void FixedUpdate()
     {
         timer -= Time.deltaTime;
         if (timer <= 0.0f)
         {
             timer += Constants.cannonRotationTime;
 
             //transform's initial (z) rotation is 45
             transform.Rotate(0.0f, 0.0f, 90);
             int angle = (int)transform.rotation.eulerAngles.z;
             Debug.Log("Angle: " + angle + ", direction: " +
             (Constants.rotDirection.ContainsKey(angle) ?
                 Constants.rotDirection[angle] : "*NOT FOUND*"));
         }
 
 
There is another odd thing. If I set the initial (Z) rotation of the game object to 135 all the values are found, it rotates to 45 instead of 44: 
Now, if I set it as 225 or 315, no new rotation makes sense, this is what I get: 
Why is this happening and how can I avoid it?
 
                 
                capture-20200505-03.png 
                (22.5 kB) 
               
 
                
                 
                capture-20200505-02.png 
                (24.1 kB) 
               
 
              
               Comment
              
 
               
              Your answer
 
 
              koobas.hobune.stream
koobas.hobune.stream 
                       
                
                       
			     
			 
                