I am trying to get
transform.rotation.z to chase the mouse pointer at a rotation speed. But I get a very weird results and can't figure out what I am doing wrong.
var mp = Input.mousePosition; var camZ = Camera.main.transform.position.z; // Grab the current mouse position on the screen. // Subtract the cams Z from the mouse Z to get ground plane. var mousePos = Camera.main.ScreenToWorldPoint ( new Vector3 (mp.x, mp.y, mp.z - camZ)); //Rotates toward the mouse var targetEuler = new Vector3 (0, 0, Mathf.Atan2 ((mousePos.y - transform.position.y), (mousePos.x - transform.position.x)) * Mathf.Rad2Deg - 90); transform.eulerAngles = new Vector3 (0, 0, Mathf.Lerp (transform.eulerAngles.z, targetEuler.z, Time.deltaTime * rotationSpeed));