- Home /
 
Limiting Rotation x of Main Camera
Hello, I'm self teaching myself Unity, and I can't figure out why this code won't work. I'm trying to limit the X Rotation of my Main Camera, so that it won't do flips. Here's the part of my code that matters.
 function Look(){
     LookVector = Vector2 ( Input.GetAxis ("Mouse X") , Input.GetAxis ("Mouse Y") );
 }
 
 
 function Movement(){
     
     var camAngleX = Camera.main.transform.eulerAngles.x;
     Camera.main.transform.Rotate( -LookVector.y * Time.deltaTime * Look_Sensitivity , 0 , 0);
     Mathf.Clamp(camAngleX , -90 , 90);
     Debug.Log (camAngleX);
 
     
 }
 
               What happens in-game, is that when I look around, I can still do flips. Thank you.
               Comment
              
 
               
               
               Best Answer 
              
 
              Answer by _Gkxd · Jul 10, 2015 at 07:12 PM
Mathf.Clamp returns the clamped value. It doesn't actually change the value that you pass in to it. For example
 float x = 5;
 float y = Mathf.Clamp(5, 0, 2);
 // x == 5, y == 2
 // now set your camera rotation to the clamped value
 
              Well, thank you very much. $$anonymous$$y whole morning just went to waste over this simple thing. Have a good day!
Your answer