- Home /
How to restrict first person from turning 360 degrees when sitting?
I'm trying to not allow my player to fully turn when he is sitting down but can't get it to work. I have the up/down axis working and restricts it to -35, 35, but when trying to restrict the left/right axis it doesn't work and no errors are thrown. Here is my code with the left/right axis stuff commented out.
 public class MouseLook : MonoBehaviour
 {
     public float mouseSensitivity = 100f;
 
     public Transform playerBody;
 
     private float xRotation = 0f;
     float yRotation = 0f;
     // Start is called before the first frame update
     void Start()
     {
         //removes cursor from view
         Cursor.lockState = CursorLockMode.Locked;
     }
 
     // Update is called once per frame
     void Update()
     {
         //set the mouse x&y movement
         float mouseX = Input.GetAxis("Mouse X") * mouseSensitivity * Time.deltaTime;
         float mouseY = Input.GetAxis("Mouse Y") * mouseSensitivity * Time.deltaTime;
         //decrease xRotation based on mouseY
         xRotation -= mouseY;
         
         
         if (PlayerMovement.isSitting)
         {
             //restricts the player from turning their head too far up/down
             xRotation = Mathf.Clamp(xRotation, -35, 35);
           //  yRotation = Mathf.Clamp(yRotation, -35, 35);
         }
         else
         {
             xRotation = Mathf.Clamp(xRotation, -60f, 60f);
           //  yRotation = 0f;
         }
         
         transform.localRotation = Quaternion.Euler(xRotation, yRotation, 0f);
         //move player left/right when mouse is going across x axis
         playerBody.Rotate(Vector3.up * mouseX);
     }
 }
               Comment
              
 
               
              Is there a reason the line yRotation = $$anonymous$$athf.Clamp(yRotation, -35, 35);is commented out? 
Answer by Xsqueezit · Jun 03, 2020 at 10:56 PM
Wouldn't this be a Z rotation for left and right given that the perpendicular axis is Z?
Your answer
 
 
             Follow this Question
Related Questions
How can I un-invert my first person spaceship controls in C#? 1 Answer
How do you force the player to look forward/toward an object? 0 Answers
NPC movement 1 Answer
First Person Player 3 Answers
 koobas.hobune.stream
koobas.hobune.stream 
                       
                
                       
			     
			 
                