Rotate towards another object

Hi. I’m new to Unity and having a small problem. I am making a 2D game so I am using an orthographic camera and planes to put textures on. I am also using Sprite Manager 2 to create these planes, if that matters. Here’s the issue I am having.

I have a ball bouncing around a room. I have a characters face and a separate plane for each eye. The eye has some blank space with the pupil at the top of the plane, so if you rotate the plane around it looks like the eye is moving around. I want the eye to follow the ball, so I just need to get it to rotate to angle that the ball is at in relation to the eye. I found some code on here, but it doesn’t seem to work perfectly. It does rotate towards the ball, but it’s constantly twitching and looks funny. Here’s the code I have. Is this the correct way to do it? If so, why would it be these sudden sharp jumps to rotations that do not point at the ball, then back to the ball giving it a twitching look?

Vector3 localTarget = thisTransform.InverseTransformPoint(target.position);
float targetAngle = Mathf.Atan2(localTarget.x, localTarget.z) * Mathf.Rad2Deg;

thisTransform.Rotate(0, 0, -targetAngle);

target is set to the ball

thanks is advance

Never used it, but try “SmoothLookAt”.
Its in the Standard Assets Folder.

Regards, Robert

Is that anything like the regular lookAt? because that didn’t work for me. That wanted to aim the face of the plane at the object so you couldn’t even see it half the time cause it was rotating it in all directions

I figured it out. The example I was getting that from was rotating in Y and I wanted to rotate in Z. So when I set targetAngle, I just had to replace localTarget.z with localTarget.y and all was well.

Glad you made it work.
So are you saying you use the script in your first post but modified?

All the best, Robert