Search Unity

Game ignores script

Discussion in 'Scripting' started by SUOS2007, Jul 3, 2020.

  1. SUOS2007

    SUOS2007

    Joined:
    Jun 5, 2020
    Posts:
    3
    I'm having trouble with clamping rotation in an fps, and it's almost as if my project was completely ignoring my script, can someone tell me why it's not clamping at maxAngle?
    Code (CSharp):
    1. public class Look : MonoBehaviour
    2.     {
    3.         public static bool cursorLocked = true;
    4.  
    5.         public Transform player;
    6.         public Transform Cam;
    7.  
    8.         public float xSensitivity;
    9.         public float ySensitivity;
    10.         public float maxAngle;
    11.  
    12.         private Quaternion CamCenter;
    13.  
    14.         void Start()
    15.         {
    16.             CamCenter = Cam.localRotation;
    17.         }
    18.  
    19.         void Update()
    20.         {
    21.             SetY();
    22.             SetX();
    23.             UpdateCursorLock();
    24.         }
    25.  
    26.         void SetY()
    27.         {
    28.             float t_input = Input.GetAxis("Mouse Y") * ySensitivity * Time.deltaTime;
    29.             Quaternion t_adj = Quaternion.AngleAxis(t_input, -Vector3.right);
    30.             Quaternion t_delta = Cam.localRotation * t_adj;
    31.            
    32.             if (Quaternion.Angle(CamCenter, t_delta) < maxAngle);
    33.             {
    34.                 Cam.localRotation = t_delta;
    35.             }
    36.         }
     
  2. PraetorBlue

    PraetorBlue

    Joined:
    Dec 13, 2012
    Posts:
    7,913
    First step is sprinkle your code with Debug.Log() calls to make sure it's actually running. If you see that logs you expect, and it's still not working, we can start digging into the logic.
     
    Joe-Censored and Kurt-Dekker like this.