Question by 
               MattPribel · Aug 25, 2015 at 09:56 PM · 
                cameracamera rotatecamera-lookclamped rotation  
              
 
              How to clamp horizontal rotation of the camera?
Hi, maybe you can help me with this. I want to add some horizontal clamp to the Unity's MouseLook script from the Standard Assets by copy and edit the ClampRotationAroundXAxis function that is already in there. After a lot of tryings I give up. Maybe I should use another technique but my scripting skills are just not high enough to solve the problem.
               Comment
              
 
               
              Hi,
The Script I use:
 public GameObject Camera01;
 public float lookSensitivity = 5f;
 public float xRotation;
 public float yRotation;
 public float currentXRotation;
 public float currentYRotation;
 public float xRotationV;
 public float yRotationV;
 public float lookSmoothDamp = 0.1f;
 //Init
 void Start()
 {
       
 }    
 //FixedUpdate
 void FixedUpdate()
 {
     xRotation -= Input.GetAxis ("$$anonymous$$ouse Y") * lookSensitivity;
     yRotation += Input.GetAxis ("$$anonymous$$ouse X") * lookSensitivity;
     xRotation = $$anonymous$$athf.Clamp(xRotation, -90, 90);
     currentXRotation = $$anonymous$$athf.SmoothDamp (currentXRotation, xRotation, ref xRotationV, lookSmoothDamp);
     currentYRotation = $$anonymous$$athf.SmoothDamp (currentYRotation, yRotation, ref yRotationV, lookSmoothDamp);
     transform.rotation = Quaternion.Euler(0, currentYRotation, currentXRotation);       
 }
 
                  But I cant get the character rotate with the camera. Hope I help :p
Answer by YoloJoe · Jan 30, 2016 at 02:46 PM
Did you try this?
 yRotation = Mathf.Clamp(yRotation, -90,90);
 
              Just put it below xRotation = $$anonymous$$athf.Clamp(xRotation, -90,90);
Your answer