Script to rotate object stops working when the X is greater than its own.
I have an object that rotates to face another object. However, when the object that rotates' x value goes over the x value of the other object, the object flips around and points away from the object. I can't figure out what's causing this, and how to fix it.
void FixedUpdate()
{
Vector2 direction = object1.transform.position - transform.position;
Quaternion rotation = Quaternion.LookRotation(direction);
transform.rotation = rotation;
transform.rotation = new Quaternion(0.0f, 0.0f, transform.rotation.z, transform.rotation.w);
}
Comment
Your answer