- Home /
360° Roation in one min
Hey there, what's a good way to let a dynamic light (sun) rotate 360° in a specific amount of time.
I'm trying it with Quaternion.Slerp but the sun doesn't rotate when i increase the end position to exactly 360° (i guess because the transform rotation would be the same).
IEnumerator DayCycle()
{
float time = 0;
float duration = 10f;
Quaternion start = Quaternion.Euler(80,-25,0); // start rot
Quaternion end = Quaternion.Euler(440, -25, 0); // stop rot (+360° on x-axis)
while (time < duration)
{
sun.rotation = Quaternion.Slerp(start,end, (time / duration));
time += Time.deltaTime;
yield return null;
}
sun.transform.rotation = end;
}
Some ideas would be great :)
Greets
Answer by hexagonius · Jan 28, 2017 at 01:18 PM
I would use Rotate. That way, you define the axis about which the sun should rotate and by how much. You're right about your assumption that two rotations, no rotation and a 360 degree rotation result in basically the same rotation. A Quaternion only knows rotations and the way from one to the other, but nothing about any intents that this should happen in a 360 degree manner.
With Rotate, you define the delta, so that you can rotate "by" whatever amount you want.