- Home /
 
               Question by 
               prateekkp · Aug 26, 2014 at 11:27 AM · 
                rotationquaternioncubeeuler  
              
 
              Rotate a cube by 90 degree
Hi I am trying to rotate a cube by 90 horizontally or vertically depending upon user input. But its all confusing the cube's rotation is behaving awkwardly. 
Currently i am using this messed up code...
 void Update ()
         {
                 if (Direction != SwitchDirection.None) {
                         SwitchMap (Direction);            
                 }
                     
 
         }
 
         void OnGUI ()
         {
                 if (GUI.Button (new Rect (Screen.width / 2, Screen.height - Screen.height / 10, 100, 100), "D")) {
                         Direction = SwitchDirection.Down;
                 }
                 if (GUI.Button (new Rect (Screen.width / 2, Screen.height / 40, 100, 100), "U")) {
                         Direction = SwitchDirection.Up;
                 }
                 if (GUI.Button (new Rect (0, Screen.height / 2, 100, 100), "L")) {
                         Direction = SwitchDirection.Left;
                 }
                 if (GUI.Button (new Rect (Screen.width - Screen.width / 10, Screen.height / 2, 100, 100), "R")) {
                         Direction = SwitchDirection.Right;
                 }
 
         }
 
         void SwitchMap (SwitchDirection switchDirection)
         {
 
                 string direction = string.Empty;
                 float directionValue = 0;                    
 
                 switch (switchDirection) {
                 case SwitchDirection.Up:
                         direction = "x";                    
                         directionValue = transform.rotation.eulerAngles.x - 90;
                         
                         break;
                 case SwitchDirection.Right:
                         direction = "z";
                         directionValue = transform.rotation.eulerAngles.z + 90;
                         break;
                 case SwitchDirection.Down:
                         direction = "x";
                         directionValue = transform.rotation.eulerAngles.x + 90;
                         break;
                 case SwitchDirection.Left:
                         direction = "z";
                         directionValue = transform.rotation.eulerAngles.z - 90;
                         break;
                 }                                
 
                 if (switchDirection != SwitchDirection.None) {
                         iTween.RotateTo (gameObject, 
                              iTween.Hash (direction, directionValue,
                                                   "time", 0.5,
                                                   "easetype", iTween.EaseType.easeInBack
                         ));
                 }    
 
                 Direction = SwitchDirection.None;
         }
 
 
                 
                cube-rotation.jpg 
                (28.5 kB) 
               
 
              
               Comment
              
 
               
               
               Best Answer 
              
 
              Answer by prateekkp · Aug 26, 2014 at 01:07 PM
I got it. The solution is here. http://forum.unity3d.com/threads/rotating-object-on-2-axis.86174/
Your answer
 
 
             Follow this Question
Related Questions
Trying to tween the rotation of a cube in x and z and having trouble 2 Answers
Calculate rotation angle for two side of cube ( like dice ) from Quaternion.identity 0 Answers
Rotation with a slider 2 Answers
How make child object rotate inverse to its parents rotation ? 1 Answer
Is there no way to get reliable angles from a rigidbody? 2 Answers
 koobas.hobune.stream
koobas.hobune.stream 
                       
                
                       
			     
			 
                