Need help with Quaternion, what is the W parameter for?

So i have this script where i rotate the instantiated bullet to the players rotation so it is rotated the right direction, and then add force to the bullet in its own rotation, then i also add some recoil or bulletspread on the y axis on the rotation. But when i move and rotate the player the bullet goes in random directions. I think the problem is in the w parameter in the rotation of the bullet. I do not quite know what its for. If i set it to 0 there is not bulletspread and the bullet only goes one direction. Any help is welcome!

					nextFire = Time.time + fireRate;
					//spawn bullet
					ammo--;
					GameObject spawnedBullet2 = Instantiate (bulletPrefab) as GameObject;
					spawnedBullet2.GetComponent<Laser> ().laserDamage = damage;
					spawnedBullet2.transform.position = spawnPos.transform.position;

					Rigidbody rb1 = spawnedBullet2.GetComponent<Rigidbody> ();
					Quaternion rot = new Quaternion(transform.rotation.x, spawnPos.transform.rotation.y + Random.Range (-recoil, recoil), spawnPos.transform.rotation.z, 2);
					spawnedBullet2.transform.rotation = rot;
					rb1.AddForce (spawnedBullet2.transform.forward * 1000);

Quaternion is based on mathematical complex numbers and is represented by four components x, y, z, w with the formula:

Q = w + xi + yj + zk

For i, j, k are virtual components, which are considered as three unit vectors of the corresponding coordinate axes. To get a deeper understanding of Quaternion, you need a certain amount of mathematical knowledge about complex numbers, trigonometric functions, and so on.

In Unity, all rotation of the object is stored and expressed by Quaternion with 4 components mentioned above. These components should not be edited independently for normal programmers.

Working with Quaternion through 4 channels x, y, z, w is really something vague and confusing. Therefore, Unity provides methods that we can manipulate through the three coordinate axes of that object.

Quaternion

Learn Quaternion

Good day @carlqwe !

If you need to operate and change rotations for a weapon, i recommend you to use the Quaternion.eulerAngles . Which only have 3 variables and are more easy to operate.

If helps, upvote !!

And if need more help, just ask using @tormentoarmagedoom !

Bye:D