Note, this happens on click and not in the update cycle
I have a game object that i rotate at a given angle, around a point without a time component like this(works as intended):
void Rotate(a)
{
var parent = transform.parent;
Vector3 point = new Vector3(0, 0, 0);
Vector3 axis = new Vector3(0, 0, 1);
parent.transform.RotateAround(Pivot.bounds.center, axis, a);
}
note that the parent is an empty to manipulate the anchor point
I wish to animate the rotation over time, however each method produces an inaccurate result. The two functions I have tried:
IEnumerator RotateOverTime(float byAngles, float inTime)
{
var parent = transform.parent;
Vector3 axis = new Vector3(0, 0, 1);
var stepAngle = byAngles/ (inTime/ 1000f);
float timer = 0;
while (timer <= (inTime/ 1000f))
{
parent.transform.RotateAround(Pivot.bounds.center, axis, stepAngle * Time.deltaTime);
timer += Time.deltaTime;
yield return null;
}
yield return null;
}
IEnumerator RotateMe(Vector3 byAngles, float inTime)
{
var parent = transform.parent;
var fromAngle = parent.transform.rotation;
var toAngle = Quaternion.Euler(parent.transform.eulerAngles + byAngles);
for (var t = 0f; t < 1; t += Time.deltaTime / inTime)
{
parent.transform.rotation = Quaternion.Lerp(fromAngle, toAngle, t);
yield return null;
}
}
The Problem:
The above two methods doesn't rotate the object by the exact amount of degrees, see image below where the angle in question is 90deg. You can clearly see by the grid what the issue is