I’m using a script to aim the gun of my UFO to the mouse position. It should aim at the mouse x and y. The z position should be at 0. The problem is that when the mouse is above or under the gun it starts to rotate. How do I restrict this rotation?
I have tried adding a rigidbody and then restricted. All the scripts seem to do this that i searched for.
here’s my code:
function Update () {
var mousePos = Input.mousePosition;
var worldPos = Camera.mainCamera.ScreenToWorldPoint(mousePos);
worldPos.z=0;
transform.LookAt(worldPos);
}