- Home /

# How to make the camera rotation stop at an exact angle?

Hey, im working on a character movement script. I've got a problem with limiting my camera rotation. The script actually limites the rotation of the camera, but not exactly at the point i'd like to. Instead of stopping the camera at 0.3 (or -0.3), it does stop it at 0.3x (or -0.3x) which completly blocks the camera rotation. Any tips?

```
using UnityEngine;
using System.Collections;
public class Movements : MonoBehaviour
{
public float speed = 10.0F;
public float RotSpeed = 150.0F;
void Update()
{
// Getting axises
float forwardBackward = Input.GetAxis("Vertical") * speed * Time.deltaTime;
float leftRight = Input.GetAxis("Horizontal") * speed * Time.deltaTime;
float RotLeftRight = Input.GetAxis("Mouse X") * RotSpeed * Time.deltaTime;
float RotUpDown = Input.GetAxis("Mouse Y") * RotSpeed * Time.deltaTime;
// Doing movements
transform.Translate(0, 0, forwardBackward);
transform.Translate(leftRight, 0, 0);
transform.Rotate (0, RotLeftRight, 0);
if(transform.rotation.x > -0.3 && transform.rotation.x < 0.3)
transform.Rotate(RotUpDown, 0, 0);
}
}
```

**Answer** by clunk47
·
Dec 16, 2012 at 10:02 PM

Try using local euler angles instead of transform rotation. I noticed the camera look on the mouse Y axis was getting stuck. Try this.

```
using UnityEngine;
using System.Collections;
public class Movements : MonoBehaviour
{
public float speed = 10.0F;
public float RotSpeed = 150.0F;
public float minY = -30.0f;
public float maxY = 30.0f;
float forwardBackward;
float leftRight;
float RotLeftRight;
float RotUpDown;
Vector3 euler;
void Start()
{
}
void Update()
{
transform.localEulerAngles = euler;
// Getting axes
forwardBackward = Input.GetAxis("Vertical") * speed * Time.deltaTime;
leftRight = Input.GetAxis("Horizontal") * speed * Time.deltaTime;
RotLeftRight = Input.GetAxis("Mouse X") * RotSpeed * Time.deltaTime;
RotUpDown = Input.GetAxis("Mouse Y") * RotSpeed * Time.deltaTime;
// Doing movements
transform.Translate(0, 0, forwardBackward);
transform.Translate(leftRight, 0, 0);
euler.y+= RotLeftRight;
euler.x+= RotUpDown;
if(euler.x >= maxY)
euler.x = maxY;
if(euler.x <= minY)
euler.x = minY;
}
}
```

Note that using angles ins$$anonymous$$d of rotation will also keep the camera from "tilting".

### Your answer

### Welcome to Unity Answers

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.