I have A lot of gameobjects on scene I need to rotate. They are AI spaceships.
However this:
Vector3 targetVector = targetPosition - myTransform.position;
float angle = Mathf.Atan2(targetVector.y, targetVector.x) * Mathf.Rad2Deg;
Quaternion q = Quaternion.AngleAxis(angle, Vector3.forward);
myTransform.rotation = Quaternion.Lerp(myTransform.rotation, q, 5.0f);
Is soo performance HEAVY that there is no way I can use it. Is there some better way to rotate sprite towards target? (Mathf.Atan2 and Mathf.Rad2Deg are taking like 30fps with 1000+ objects)
↧