- Home /
 
 
               Question by 
               crace96 · Mar 12, 2018 at 01:30 AM · 
                rotationcamera rotatecamera rotation  
              
 
              First person camera- Limit X-axis rotation.,How to Limit Camera rotation on X-Axis
public class MouseLook : MonoBehaviour { Vector2 mouseLook; Vector2 smoothV; public float sensitivity = 5.0f; public float smoothing = 2.0f;
 GameObject character;
 // Use this for initialization
 void Start()
 {
     character = this.transform.parent.gameObject;
 }
 // Update is called once per frame
 void Update()
 {
     var md = new Vector2(Input.GetAxisRaw("Mouse X"), Input.GetAxisRaw("Mouse Y"));
     md = Vector2.Scale(md, new Vector2(sensitivity * smoothing, sensitivity * smoothing));
     smoothV.x = Mathf.Lerp(smoothV.x, md.x, 1f / smoothing);
     smoothV.y = Mathf.Lerp(smoothV.y, md.y, 1f / smoothing);
     mouseLook += smoothV;
     transform.localRotation = Quaternion.AngleAxis(-mouseLook.y, Vector3.right);
     character.transform.localRotation = Quaternion.AngleAxis(mouseLook.x, character.transform.up);
 }
 
               }
I have this script on my camera and the camera is attached to my playermodel in a first person view. I want to limit the rotation on the x axis between two values so when i am looking down it doesnt clip into my character or flip around 360 degrees
               Comment
              
 
               
              Your answer
 
             Follow this Question
Related Questions
Unity Rotate Around and Orbit Question 0 Answers
MoveRotation stops working while player is moving 0 Answers
How to make the player rotate to where an object is being thrown? 1 Answer
How do I rotate player's camera to peak around objects. (first person shooter leaning) 1 Answer
Camera rotation 0 Answers