# Quaternions not exact

Hello , sooo i am new to quaternion and i’ve been trying hard to understand them … I want to smoothly rotate a cube a 90 degrees so I did the following :

using UnityEngine;
using System.Collections;

public class TriggerRotator : MonoBehaviour {

``````private GameObject cube;
private bool startRotation;
float counter = 0;
public Quaternion from;
public Quaternion to;

// Use this for initialization
void Awake() {

cube = GameObject.FindGameObjectWithTag("Plateform");

//from = new Quaternion(0, 0, 0, 1);
//to = new Quaternion(0, 0, 0, 1);
//from.SetEulerAngles(0, 0, 0);
//to.SetEulerAngles(1f, 0, 0);

from = new Quaternion(0, 0, 0, 1);
to = new Quaternion(1.0f, 0, 0, 1);

//from.SetEulerAngles(0, 0, 0);
//to.SetEulerAngles(1f, 0, 0);

//this

}

// Update is called once per frame
void Update () {

Debug.Log(from.eulerAngles);

if(startRotation)
{
cube.transform.rotation = Quaternion.Slerp(from, to, counter);
counter += 0.01f;

}

}

void OnTriggerEnter(Collider other)
{

if(other.gameObject.tag=="Player")
{
Debug.Log("entered");
startRotation = true;
// cube.transform.Rotate(40, 0, 0);

}
}
``````

}

the code is running but the cube reaches only 89.981 degrees
How can i do to make it a sharp 90 degrees ?
Thanks for all

Your quaternion is not normalized. As elenzil said you usually use either the Euler, AngleAxis, FromToRotation or LookRotation method to construct a quaternion. However if you want to create it manually you should know how it works under the hood.

So if you want to rotate around a given vector “v” by the angle of “a” you would do:

``````float radians = a * Mathf.Deg2Rad;
v = v.normalized * Mathf.Sin(radians / 2);
Quaternion q = new Quaternion(v.x, v.y, v.z, Mathf.Cos(radians / 2));
``````

This does exactly the same as `Quaternion.AngleAxis(a, v);`

So as an example with numbers if you want to rotate around the x axis by an angle of 90° you would get

``````new Quaternion(0.70710678f, 0f, 0f, 0.70710678f);
``````

`0.70710678f` is sin(45°) or “1 / sqrt(2)”

As you can see the resulting quaternion is always normalized as it’s “length” is `1.0` at all times. In this example since “0.70710678f” is the inverse of the square root of 2 when you square it you get “0.5”. 0.5 + 0 + 0 + 0.5 == 1.0.