- Home /
How to rotate about 360 on a coroutine
Hi everyone.
I can’t figure out the right way to rotate my object of 360 degrees in a coroutine.. anyone can help me please?
Thank you in advance
Answer by Sylon87 · Nov 29, 2018 at 12:09 PM
I did it with Transform.Rotate, then check the quaternion angle, and when it reach the target the loop will stop.
That’s all.
Answer by JannickL · Nov 28, 2018 at 11:47 AM
Hi, try this (you just have to start the coroutine):
IEnumerator Rotate(float duration)
{
float startRotation = transform.eulerAngles.y;
float endRotation = startRotation + 360.0f;
float t = 0.0f;
while ( t < duration )
{
t += Time.deltaTime;
float yRotation = Mathf.Lerp(startRotation, endRotation, t / duration) % 360.0f;
transform.eulerAngles = new Vector3(transform.eulerAngles.x, yRotation,
transform.eulerAngles.z);
yield return null;
}
}
Answer by mlnczk · Nov 28, 2018 at 11:34 AM
Hey! Its pretty weird and tricky question but I think the best way will be using iTween asset that helps you with movement and rotations. Its completly free and easy to use. Also its a good tool to use it instead of animations. For example if you got something simple like button moving on X axis etc. you can tween it instead of creating animator, animator controller. Its much lighter for compiling. https://assetstore.unity.com/packages/tools/animation/dotween-hotween-v2-27676
Thank’s you for your reply. Actually i prefer to understand how to do it ins$$anonymous$$d of using this kind of tool :)
Your answer
Follow this Question
Related Questions
Flip over an object (smooth transition) 3 Answers
Wrong rotation while moving 1 Answer
transform.Rotate will not work 1 Answer
Distribute terrain in zones 3 Answers
help me to rotate an object 1 Answer