# Rotation doesn't stop after hitting bounds

I have a simple problem I just don’t understand.
I want to rotate my camera up and down (around x-axis) with a 0° and 90° as bounds.
Here is the part of the script:

``````        if (Input.GetKey(KeyCode.W) && this.transform.localRotation.x > 0f)
{
this.transform.Rotate(Vector3.left * 0.5f * rotateSpeed * Time.deltaTime);
}

if (Input.GetKey(KeyCode.S) && this.transform.rotation.x < 90f)
{
this.transform.Rotate(Vector3.right * 0.5f * rotateSpeed * Time.deltaTime);
}
``````

When I rotate it with “W” it stops when rotation hits 0. When I rotate it with “S” it just keeps rotating untill I release “S”. Any suggestions?

Don’t think you want to check the rotation.x … This is a Quaternion (x,y,z,w) value, NOT a rotation around an axis. To check rotation around an axis, you want to look at the EulerValues of the transform.rotation.

e.g `(this.transform.localEulerAngles.x < 90f)`
or `(this.transfor.rotation.eulerAngles.x)` //the Quaternion class version

Here is my final code:

``````if (Input.GetKey(KeyCode.W) && (cam.transform.localRotation.x > 0f && cam.transform.localRotation.x < 91f))
{
cam.transform.Rotate(Vector3.left * 0.5f * rotateSpeed * Time.deltaTime);
}

if (Input.GetKey(KeyCode.S) && (cam.transform.localEulerAngles.x < 90f || cam.transform.localEulerAngles.x > 350f))
{
cam.transform.Rotate(Vector3.right * 0.5f * rotateSpeed * Time.deltaTime);
}
``````

Works this way, the new bounds are because it doesn’t stop at 0° but around 359° so I had to change that. But I don’t know why it only works with mixing localEulerAngles and Rotation.