Problem with Quaternion in unity

I make a 2d shooter, the gun turns depending on the cursor, if we press the lmb, then a bullet is created, which takes the arguments: start.position and pistol.transform. rotation

Instantiate(bollet, StartPos.position, pistol.transform.rotation);

I decided to make a spread by adding the number four to transform.rotation, but I can't add anything directly to transform.rotation. Solved the problem like this:

  Quaternion rot = Quaternion.Euler(pistol.transform.rotation.x, pistol.transform.rotation.y, pistol.transform.rotation.z+4);
Instantiate(bollet, StartPos.position, rot);

But in this case, the bullet flies to the right + 4. When I output pistol. transform.rotation. z, it is output a number that does not reach one and minus one, i.e. -0.9835, 08953, and so on. (Usually in these values). What to do?

 0
Author: Фёдор, 2020-01-29

1 answers

I don't quite understand what you want to do, but I can explain the error with degrees.

Transform.rotation. x (/y/z) - returns the rotation not in degrees, but in the boundary [-1; 1]

Function Quaternion.Euler() takes exactly the values in degrees. To get the rotation value in degrees, write transform.rotation. eulerAngles. x (/y/z)

 2
Author: KuzCode, 2020-01-29 20:03:40