# Rotation left & right

Hello everyone,

I don’t understand why my camera can rotate on the left and not on the right, here my code :

``````float angle = Mathf.MoveTowardsAngle(transform.eulerAngles.y, transform.eulerAngles.y, Input.GetAxis("Mouse X")*50*Time.deltaTime);

transform.eulerAngles = new Vector3(transform.eulerAngles.x,angle, transform.eulerAngles.z);
``````

Thank for your help

I don’t understand why it even partially works.

You need to put the mouse input in the second argument (target) of Mathf.MoveTowardsAngle.

Right now you are moving transform.eulerAngles.y toward transform.eulerAngles.y, and that can’t do any good.

With the limited amount of code here, I cannot figure out what is going wrong, but I do know that anytime I deal with eulerAngles, there are issues that I have to jump through. Let me give you an alternate way to solve your problem.

If you take either a screen point or a world point and convert it to viewport point, you can tell where the point is relative to the camera view. Values greater than 0 and less than 1 are seen by the camera.

Here is a sample script. Attach it to the camera in a new scene with some object to give you feedback about the camera rotation:

``````public class RotateEdges : MonoBehaviour {

private Vector3 v3Rot = new Vector3(0.0f,1.0f,0.0f);

void Update () {
Vector3 v3Pos = Input.mousePosition;
v3Pos.z = 10;
v3Pos = Camera.main.ScreenToViewportPoint (v3Pos);

if (v3Pos.x < 0.1)
transform.Rotate(-v3Rot);
else if (v3Pos.x > 0.9)
transform.Rotate(v3Rot);
}
}
``````

Note the v3Pos I calculate with a ScreenToViewportPoint() call could also be done by using a point in the scene and a WorldToViewporotPoint() call.

If this does not work the way you want it to, reply to this post with the issues, and I’ll give you alternate approaches.