How can I limit the rotation on My y-axis for My camera? My movement code is:

```
var rotateSpeed : float = 3.0;
function Update () {
transform.localEulerAngles.x -= Input.GetAxis("Mouse Y") * rotateSpeed;
}
```

Thanks in advance!

How can I limit the rotation on My y-axis for My camera? My movement code is:

```
var rotateSpeed : float = 3.0;
function Update () {
transform.localEulerAngles.x -= Input.GetAxis("Mouse Y") * rotateSpeed;
}
```

Thanks in advance!

First, a quote from the reference on [localEulerAngles][1]:

*Only use this variable to read and set the angles to absolute values. Donâ€™t increment them, as it will fail when the angle exceeds 360 degrees.*

Typically the way I write code to deal with eulerAngles and localEulerAngles is to maintain my own Vector3 and assign but never read from eulerAngles. For most rotations, there are more than one euler angle representation, so you cannot depend on the values.

```
var v3Rotate = Vector3.zero;
var min = -50;
var max = 50;
var rotateSpeed : float = 45.0;
function Start() {
transform.localEulerAngles = v3Rotate;
}
function Update () {
v3Rotate.x += Input.GetAxis("Mouse Y") * rotateSpeed * Time.deltaTime;
v3Rotate.x = Mathf.Clamp(v3Rotate.x, min, max);
transform.localEulerAngles = v3Rotate;
}
```

You can use Quaternion.RotateTowards(Quaternion from, Quaternion to, float maxDegreesDelta) function to restrict rotation:

```
Quaternion ClampRotationYByLookDirection(Quaternion curentRotation)
{
Vector3 lookDirectionY = Vector3.ProjectOnPlane(lookDirection, Vector3.up).normalized;
Quaternion lookRotation = Quaternion.LookRotation(lookDirectionY);
Quaternion towardsRotation = Quaternion.RotateTowards(lookRotation, curentRotation, lookDeltaY);
return towardsRotation;
}
```