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