# Quaternion.LookRotation Returning Undesired Rotation

I have a top-down 2D game (constrained to xy-plane), and I’m trying to use Quaternion.LookRotation to rotate the player based on the position of the mouse.

Here is a screen recording of the problem: 1.

I suspect the transformation is giving me undesired results since my up and look vectors for the camera are different than default.

``````// This code is in the FixedUpdate() of the PlayerBehavior component
// attached to the player object.
Vector3 mousePosition = Camera.main.ScreenToWorldPoint(Input.mousePosition);
Vector3 lookVector = (mousePosition - transform.position);
lookVector.z = 0.0f;
transform.rotation = Quaternion.LookRotation(lookVector, new Vector3(0.0f, 0.0f, -1.0f));

// Since I only want the player to be rotated with respect to the z-axis,
// the x and y components of the rotation are zeroed out.
transform.eulerAngles = new Vector3(0.0f, 0.0f, transform.eulerAngles.z);
``````

The resulting transformation rotates my player in unusual, unexpected ways that do not resemble my desired result. The intention is for the mouse to rotate the player similar to games like Hotline Miami.

For reference, my up vector is (0, 0, -1), my camera is at (0, 0, -1), my camera’s look vector is (0, 0, 1).

Directly manipulating the components of a Quaternion is problematic. The most common solution posted on Unity Answers (and it’s been posted many times) is as follows:

`````` Vector3 screenPos = Camera.main.WorldToScreenPoint(transform.position);
Vector3 dir = Input.mousePosition - screenPos;
float angle = Mathf.Atan2(dir.y, dir.x) * Mathf.Rad2Deg;
transform.rotation = Quaternion.AngleAxis(angle, Vector3.forward);
``````

This code assumes that the ‘forward’ side of your sprite is to the right.