[SOLVED]2D lookAt is off, any ideas?

Hello everyone and thanks for your time. I recently started a small personal project and have noticed that my look at is off most of the time. It will match up sometimes but not all the time and that just won’t work for me.

The red line is leading to the mouse cursor while the blue line is where the turret is firing to.

Here is the bit of code I have doing it

lookAtPos = Camera.main.ScreenToWorldPoint(Input.mousePosition);
Quaternion rot = Quaternion.LookRotation(transform.position - lookAtPos, Vector3.forward);
		
transform.rotation = rot;
transform.eulerAngles = new Vector3(0, 0, transform.eulerAngles.z);

That is in the update function.

What side of your gun is the front when the gun has the rotation of (0,0,0)? I suspect you are looking at 2D here with the front on the right or up. If so, you cannot use LookAt() in the way you are using it here. My assuming was that since your original code was sorta working that font faces positive ‘z’ when the rotation is (0,0,0). For rotation of an object where front is the right side and the camera is facing has rotation (0,0,0), you can do:

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