- Home /
Unity3d - Transform rotation(angle) help
Im trying to rotate an object 90 degrees to the left but instead of rotating straight left it rotates 270 degrees to the right.
Here's the part of the code which controls the rotation:
rotationDestination = new Vector3(60, 270, 0);
if (Vector3.Distance(transform.eulerAngles, rotationDestination) > 0.2f)
{
transform.eulerAngles = Vector3.Lerp(transform.rotation.eulerAngles, rotationDestination, rotationSpeed * Time.deltaTime);
}
If I try to make the Y axis -90 a.k.a (60, -90, 0) then it rotates constantly to the left.
How do I make it rotate straight to the left (90 degrees) ?
Thank you.
Answer by holliebuckets · Sep 18, 2015 at 07:06 PM
Hello :) Quaternions are a bit difficult to understand at first, but they do get easier. :D
This YouTube video is a great resource for understanding how Euler Angles work (and should answer your question too!) :D
Best of Luck!!
Hey,
Thank you for your quick response but the video you shared didn't bring any help to my issue. If you have any other ideas then please don't hesitate to bring it up!
Thanks.
Actually it sorta helped, I fixed it by using Quaternions.
if (Quaternion.Angle(transform.rotation, Quaternion.Euler(rotationDestination)) > 0.2f)
{
transform.rotation = Quaternion.Lerp(transform.rotation, Quaternion.Euler(rotationDestination), Time.deltaTime * rotationSpeed);
}
Your answer
![](https://koobas.hobune.stream/wayback/20220612034230im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers
Illuminating a 3D object's edges OnMouseOver (script in c#)? 1 Answer
Enemy Lerping between two Vectors 1 Answer