- Home /
 
 
               Question by 
               ninjustice · Aug 14, 2015 at 11:05 PM · 
                camerarotationmathf.clamp  
              
 
              This is probably a really simple problem that I can't figure out
The yRotate value doesn't clamp. I only want to be able to look straight up and down - I don't want to be able to turn the camera a full 360 degreees. This is in an update function. the main code is too long so I just took out this part.
 using UnityEngine;
 using System.Collections;
 
 float camSensitivity = 5.0f;
 
 void Update() {
     float yRotate = 0.0f;
     yRotate -= Input.GetAxis("Mouse Y") * camSensitivity;
     Camera.main.transform.Rotate (Mathf.Clamp(yRotate, -90, 90), 0, 0);
 }
 
              
               Comment
              
 
               
              Your clamp is being updated each frame, so you will have to assign the rotate max and $$anonymous$$.
 
               Best Answer 
              
 
              Answer by nomadic · Aug 14, 2015 at 11:30 PM
You are clamping the amount you are rotating each frame, not clamping the final rotation.
Try this:
 using UnityEngine;
 using System.Collections;
      
 float camSensitivity = 5.0f;
 float yRotation = 0f;
      
 void Update() {
   yRotatation -= Input.GetAxis("Mouse Y") * camSensitivity;
   yRotation = Mathf.Clamp(yRotation, -90f, 90f);
   Camera.main.transform.rotation = Quaternion.Euler(yRotation, 0, 0);
 }
 
 
              Your answer