Help with rotation (Quaternion.Slarp) in Unity

-1

I want to make my object spin 120 degrees and set a time for it. but instead of turning 120 degrees it goes to 120 degree. How to fix it?

Transform inicial;
float tempo;
float angle;
void Start () {
    inicial = GetComponent<Transform>();
    tempo = 2.0f * Time.deltaTime; // Aki era pra ser 2 segundos
     angle = inicial.rotation.z + 120;


}

void Update () {

    transform.rotation = Quaternion.Slerp(inicial.rotation, Quaternion.Euler(0,0, angle), tempo);
}
    
asked by anonymous 19.12.2018 / 22:23

1 answer

0

First mistake: misuse of Slerp

First, you should not have carefully read the documentation for the Quaternion.Slerp function and so did not correctly understand how the third parameter works. This function makes a interpolation between two values a and b (the two the first parameters) according to the progress t (the third parameter). This progress needs to be necessarily a value between 0 and 1, so much so in the documentation itself that it is truncated ( clamped ) for that interval if it is different from it is mine):

  

Spherically interpolates between a and b by t. The parameter is clamped to the range

13.01.2019 / 16:22