So, i’m trying to rotate an object 90° around a world axis with the help of Quaternion.Slerp to make it smooth.
I’ve can do the rotation with code like this: transform.Rotate(-90, 0, 0, Space.World);
The problem with this is that it snaps to the rotation. So i tried with this code below to smooth it out, but it doesn’t work. It rotates around its own axis like, if i used Space.Self instead to Space.World.
float elapsedTime = 0.0f;
do
{
transform.localRotation = Quaternion.Slerp(m_startRotation, m_gravityRotation, elapsedTime / rotationDuration);
elapsedTime += Time.deltaTime;
yield return null;
} while (elapsedTime <= rotationDuration);
I know that it can be coded manualy, but i really want to know if there is an easy solution to this problem.
Easiest way to do this would be using Transform.Rotate in your coroutine loop, something like:
float elapsedTime = 0.0f;
do
{
transform.Rotate(-90*Time.deltaTime/rotationDuration, 0, 0, Space.World);
elapsedTime += Time.deltaTime;
yield return null;
} while (elapsedTime <= rotationDuration);
You could also do it with Quaternion.Slerp if you assign to .rotation rather than to .localRotation. But it doesn’t seem as simple or clear to me.
JoeStrout:
Easiest way to do this would be using Transform.Rotate in your coroutine loop, something like:
float elapsedTime = 0.0f;
do
{
transform.Rotate(-90*Time.deltaTime/rotationDuration, 0, 0, Space.World);
elapsedTime += Time.deltaTime;
yield return null;
} while (elapsedTime <= rotationDuration);
You could also do it with Quaternion.Slerp if you assign to .rotation rather than to .localRotation. But it doesn’t seem as simple or clear to me.
I’ve tried before with .rotation and it gave me tha same problem. I’m gonna try with what you are telling me.