How to rotate Quaternion around axis for a certain degree

Hello,
Please take a look at this animated picture :
alt text

What i want to do is to rotate the cube around one of the axis but most importantly stop it at a certain point, in this case is when the cube become orange. I know how to rotate the cube :

transform.rotation *= Quaternion.Euler (Vector3.right * speed * Time.deltaTime);

I want to know what to use in order to calculate when to stop (1/4 way in my case), i am not used with working with quaternion so any further explanation would be really appreciated.

thank you and have a nice day

Well, you could just check your transform’s euler angles before and after the rotation, add the difference to some variable, and stop rotating if that difference reaches a certain number.

Or, you could calculate how long you need to rotate at the speed you are rotating. With the code you have you are essentially rotating speed degrees per second, so you can calculate how long you need to rotate, and stop rotating when that much time has passed.

i kinda fixed the problem by setting the initial rotation of the object to (0,45,0) and instead of rotating the object to show the upper face of the cube, i moved and rotated the camera to have the same view. Like this i was able to just add 90degrees to X or Z and have the result am looking for, however, i have a new simple problem, the cube reverse its rotation direction every time, it goes to the correct rotation, but in a reversed direction, here is a GIF :
alt text

and this is my code :

using UnityEngine;
using System.Collections;
 
public class RotateCube : MonoBehaviour
{
 
        public  float speed;
        private Vector3 myEul, targetEul;
        private Transform myTrans;
        private bool canRotate;
 
        void Start ()
        {
                myTrans = transform;
                myEul = myTrans.rotation.eulerAngles;
                targetEul = myEul;
 
        }
       
 
        void Update ()
        {
       
                if (canRotate) {
                        rotationInput ();
                }
                checkRotation ();
        }
 
 
 
        void checkRotation ()
        {
                if (Vector3.Distance (targetEul, myEul) > 1.5f) {
                        myEul = Vector3.Lerp (myEul, targetEul, speed * Time.deltaTime);
                } else {
                        myEul = targetEul;
                        canRotate = true;
                }
                myTrans.rotation = Quaternion.Euler (myEul);
        }
 
 
 
        void rotationInput ()
        {
                if (Input.GetKeyDown (KeyCode.LeftArrow)) {
                        myEul = myTrans.rotation.eulerAngles;
                        targetEul = myEul;
                        targetEul.x += 90;
                        canRotate = false;
                }
        }
}

Thank you :slight_smile: