You're using the wrong Quaternion method for what you're trying to do.
It looks like you're trying to smoothly damp an angle between a min and max measured in degrees.
The new Quaternion
constructor does not take angles in degrees as its arguments. The first clue is that it asks for 4 parameters (x, y, z, w)
not three Euler angles (x, y, z)
/ (pitch, yaw, roll)
(what on Earth would a "w" angle rotate around?). These 4 parameters describe a point on a unit sphere in 4-dimensional space, so numbers like 20-40 make no sense here at all. And by leaving the w component at 0, you've ensured you can only get 0 or 180 degree rotations out of this expression.
What you want is Quaternion.Euler
, which does accept angles in degrees:
Declaration
public static Quaternion Euler(float x, float y, float z);
Description
Returns a rotation that rotates z degrees around the z axis, x degrees around the x axis, and y degrees around the y axis; applied in that order.
So your corrected code would read like this:
text.rotation = Quaternion.Euler(
0,
Mathf.SmoothStep(minimum, maximum, t),
0
);
Also, note that when you compute your time this way:
float t = (Time.time - startTime) / duration;
...you will lose precision, the longer your game has been running. A better solution is to accumulate t
, something like this:
// We can initialize this to a constant.
// Now we don't even need a Start method to populate it!
float t = 0;
void Update()
{
// Add an increment to t,
// proportionate to the high-precision time step since last frame.
t += Time.deltaTime / duration;
// ...etc.
}