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