# Unity2D problem with negative z rotation shooting bullet towards mouse click

I have what seems to me to be a very odd error, though I’m sure it’s something simple I’m missing here. I’m rather new to Unity, and as such most of my code at the moment is adopted from tutorials.

I have the following code to shoot an object from my player’s gun at where a user clicks with their mouse. The odd thing is that if I click right next to the gun, the bullet displays fine. But if I click even a small distance away the bullet rotates sideways in the z axis and is very difficult to see in the 2D view.

The bullet is fine if Z is 0 (which it is when clicking close to the player) but Z becomes progressively more negative negative the farther you click (10^-7 a short distance away and still only partially rotated, then 10^-6, then farther than that – now almost invisible in the 2D view).

I am going to be reading up on Quaternions and the like as I do not understand how Unity uses them exactly yet but if anyone could point me in the right direction it would be much appreciated.

``````public GameObject GravityLiftShot;
private Vector3 mousePos;
private Vector3 objectPos;
private float angle;
private float shotSpeed = 1000;

void FixedUpdate()
{
//Point the gun at the mouse
mousePos = Input.mousePosition;
mousePos.z = 0;
objectPos = Camera.main.WorldToScreenPoint(transform.position);
mousePos.x = mousePos.x - objectPos.x;
mousePos.y = mousePos.y - objectPos.y;
angle = Mathf.Atan2(mousePos.y, mousePos.x) * Mathf.Rad2Deg - 90;
Vector3 rotationVector = new Vector3(0, 0, angle);
transform.rotation = Quaternion.Euler(rotationVector);

//Fire!
if (Input.GetMouseButtonDown(0))
{
GameObject shot = (GameObject)Instantiate(GravityLiftShot, transform.position, transform.rotation);
shot.transform.LookAt(mousePos);
``````shot.transform.rotation = Quaternion.LookRotation(mousePos);
``````mousePos.z = 10;