Rotating Object Smoothly Exactly 90 degrees on click (for infinite rotations)
My current function does it's job, but it rotates the object with a 90+-3 degrees, which makes further multiple rotations not as accurate. I am trying to rotate the object by exactly 90 degrees. Here it is:
IEnumerator RotateTimeMachine(Vector3 byangle, float intime)
{
var froma = GetRotation(TimeMachine);
var toa = Quaternion.Euler(transform.eulerAngles + byangle);
for (var t = 0f; t < 1; t += Time.deltaTime / intime)
{
transform.rotation = Quaternion.Slerp(froma, toa, t);
yield return null;
}
}
I am calling it with: StartCoroutine(RotateTime$$anonymous$$achine(Vector3.up * 90, 0.2f));
Ins$$anonymous$$d of adding because it will make it less accurate every time you'll add something, maybe ins$$anonymous$$d set a target. So You'll create another method that calculates what the next out of fixed positions should be. also you try to optimize by first calculating the quaternion? if optimization is important also use localRotation. $$anonymous$$aybe try to use just eulerangles (localeulerangles) to make it easier, afterwards you can always optimize.
Your answer
Follow this Question
Related Questions
How to limit only one axis rotation? c# 1 Answer
How to rotate object back and forth from one rotation to another? 2 Answers
Unity lookat at finger position 3D C# 0 Answers
How to make a smooth rotation? 1 Answer
how do i rotate an object? C# 1 Answer