- Home /
 
               Question by 
               David_Rios · Dec 30, 2017 at 09:47 PM · 
                c#camera3dcamera rotate  
              
 
              Limiting vertical camera rotation
I've seen multiple threads on this topic, although none of those solutions have worked for my current script. I have my camera set up so it rotates when the right mouse button is being held down and dragged. My camera moves with the WASD keys, goes up with Space, down with Left Shift.
 if(Input.GetMouseButtonDown(1))
 {
     // Get mouse origin
     mouseOrigin = Input.mousePosition;
     isRotating = true;
 }
 if (isRotating)
 {
     Vector3 pos = cameraMain.ScreenToViewportPoint(Input.mousePosition - mouseOrigin);
     transform.RotateAround(transform.position, transform.right, -pos.y * turnSpeed);
     transform.RotateAround(transform.position, Vector3.up, pos.x * turnSpeed);
 }
The error I have with this is that the camera vertically rotates freely. I want to know how to apply a limit to this y-rotation without changing the effect this code has on the camera. I've attempted the Input.GetAxis method, but this ends up moving my camera without holding down the right mouse button.
               Comment
              
 
               
              Your answer
 
 
              koobas.hobune.stream
koobas.hobune.stream 
                       
                
                       
			     
			 
                