I’m trying to use this line:
transform.rotation = Quaternion.Euler(transform.rotation.x,
transform.rotation.y,
transform.rotation.z + Input.GetAxis("Horizontal") * -roll);
to rotate an object by a speed of “roll”. Instead of the expected result, it’s rotating up to “roll”. For example if roll is 5f, then the rotation.z will only go between -5f and 5f. The Debug.Log of Input.GetAxis(“Horizontal”) clearly shows it doesn’t revert to 0 and should continue to roll the rotation.z. What am I missing here?
‘transform.rotation’ is a Quaternion. The individual x,y,z,w are not angles. They will have values between -1 and 1. You could use transform.eulerAngles instead as parameters to your Quaternion.Euler() call, but typically the rotation you are doing here is done this way:
transform.Rotate(0,0,Input.GetAxis("Horisontal") * -roll);
or
transform.Rotate(0,0,Input.GetAxis("Horisontal") * -roll, Space.World);
Transform.Rotate() does a relative rotation. The first line rotates around the object’s local ‘z’ axis. The second line rotates around world ‘z’ axis.