I am trying to create a character selection menu but when I try to take back the rotation when another player is choosen the lerp doesn’t seem to work.
The whole dilemma is 3 lines of code:
Quaternion temp = a.transform.rotation;
temp.y = 0;
a.transform.rotation = Quaternion.Lerp(a.transform.rotation,temp,Time.time * 330.0f);
This works exactly as:
Quaternion temp = a.transform.rotation;
temp.y = 0;
a.transform.rotation = temp;
The same thing happens with Slerp.
Any idea why this happens?
Seems to me like you are running the storing oiece of the code (line 1) in the same process as the lerping part (line 3) So you end up with to Quaternion values that are the same. Except if I am misreading your code, you will need to store the rotation of a before you start the rotation process.
I guess the rotation is a.transform.rotation of the current cube and than it restarts to 0 when another object is selected.
What is wrong?
One problem is the t value used for the lerp:
Time.time * 330.0f
This will get clamped to the [0,1] range before being used. Since Time.time is the absolute time since the app started, t will only have a value less than 1 for the first 1/330th of a second of the app’s execution. I suggest you change the t value to be something like:
// When starting the lerp
timeAtStartOfLerp = Time.time;
// Value of t
(Time.time - timeAtStartOfLerp) * 330.0f
Edit: 330 is probably far too high a value to be using. It makes the duration of the lerp significantly shorter than the duration of a frame when running at 60Hz.
Wow, thanks man!
I tried it like you said and it worked 