restrict mouselook X movement script does not work

Why is it that I can restrict the mouseY movement (min and max) in the mouselook script that comes with Unity in the standard assets, but the min and max of the mouseX does not work? Any help would be great, thanks!

It seems important to allow the camera to do full rotations on X axis if needed.
Something like that will allow it ( if minimumX equals maximumX ):

 if (axes == RotationAxes.MouseXAndY) {
	if (minimumX == maximumX) {
		rotationX = transform.localEulerAngles.y + Input.GetAxis("Mouse X") * sensitivityX;
	}
	else {
		rotationX += Input.GetAxis("Mouse X") * sensitivityX;
		rotationX = Mathf.Clamp(rotationX, minimumX, maximumX);				
	}
	rotationY += Input.GetAxis("Mouse Y") * sensitivityY;
	rotationY = Mathf.Clamp (rotationY, minimumY, maximumY);
	transform.localEulerAngles = new Vector3(-rotationY, rotationX, 0);
}

I have debug the script :slight_smile:

using UnityEngine;
using System.Collections;

[AddComponentMenu("Camera-Control/Mouse Look (Debugged Edition)")]
public class MouseLook : MonoBehaviour {

	public enum RotationAxes { MouseXAndY = 0, MouseX = 1, MouseY = 2 }
	public RotationAxes axes = RotationAxes.MouseXAndY;
	public float sensitivityX = 15F;
	public float sensitivityY = 15F;

	public float minimumX = -360F;
	public float maximumX = 360F;

	public float minimumY = -60F;
	public float maximumY = 60F;

	public bool smoothLookX;
	private float sensivityXmemory;
	private float maximumSmoothX;
	private float minimumSmoothX;

	float rotationY = 0F;
	float rotationX = 0F;




	void Update ()
	{
		if (axes == RotationAxes.MouseXAndY)
		{
			//float rotationX = transform.localEulerAngles.y + Input.GetAxis("Mouse X") * sensitivityX;
			rotationX += Input.GetAxis("Mouse X") * sensitivityX;
			rotationY += Input.GetAxis("Mouse Y") * sensitivityY;
			rotationY = Mathf.Clamp (rotationY, minimumY, maximumY);
			rotationX = Mathf.Clamp (rotationX, minimumX, maximumX);


			transform.localEulerAngles = new Vector3(-rotationY, rotationX, 0);
		}
		else if (axes == RotationAxes.MouseX)
		{
			transform.Rotate(0, Input.GetAxis("Mouse X") * sensitivityX, 0);
		}
		else
		{
			rotationY += Input.GetAxis("Mouse Y") * sensitivityY;
			rotationY = Mathf.Clamp (rotationY, minimumY, maximumY);
			
			transform.localEulerAngles = new Vector3(-rotationY, transform.localEulerAngles.y, 0);
		}

		//NEBUCH
		if (smoothLookX) {
			if (rotationX > maximumSmoothX) {
				sensitivityX = 1f;
			}

			if (rotationX < minimumSmoothX){

				sensitivityX = 1f;
			}

			if (rotationX > minimumSmoothX && rotationX < maximumSmoothX){

				sensitivityX = sensivityXmemory;

			} 

		}

	}
	
	void Start ()
	{
		// Make the rigid body not change rotation
		if (GetComponent<Rigidbody>())
			GetComponent<Rigidbody>().freezeRotation = true;
		//NEBUCH
		sensivityXmemory = sensitivityX;
		maximumSmoothX = maximumX - maximumX / 5;
		minimumSmoothX = minimumX + minimumX / (-5);

	}
}

AH! Just figured it out. Anyone who wants a quick fix, feel free to copy this code... Open up the mouselook script and change this...

    float rotationY = 0F;

void Update ()
{
    if (axes == RotationAxes.MouseXAndY)
    {
        float rotationX = transform.localEulerAngles.y + Input.GetAxis("Mouse X") * sensitivityX;

        rotationY += Input.GetAxis("Mouse Y") * sensitivityY;
        rotationY = Mathf.Clamp (rotationY, minimumY, maximumY);

        transform.localEulerAngles = new Vector3(-rotationY, rotationX, 0);
    }

To this...

    float rotationX = 0F;
float rotationY = 0F;

void Update ()
{
    if (axes == RotationAxes.MouseXAndY)
    {
        rotationX += Input.GetAxis("Mouse X") * sensitivityX;
        rotationX = Mathf.Clamp (rotationX, minimumX, maximumX);

        rotationY += Input.GetAxis("Mouse Y") * sensitivityY;
        rotationY = Mathf.Clamp (rotationY, minimumY, maximumY);

        transform.localEulerAngles = new Vector3(-rotationY, rotationX, 0);
    }

I think it's a little ridiculous how they scripted this script by using variables that are never put into use. Hopefully one of the developers will get a glance of this and fix it in the next release :)

That worked a treat “alexmon27”, thanks.