Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Resolved Constantly looking down in WebGL

Discussion in 'WebGL' started by unity_fqlyjbgDafPWCw, Feb 25, 2021.

  1. unity_fqlyjbgDafPWCw

    unity_fqlyjbgDafPWCw

    Joined:
    Feb 5, 2021
    Posts:
    9
    Not sure if this is a bug, or if I'm doing something wrong as this is my first WebGL game.

    I have very basic first person movement controls, they work fine in the editor but when I build my scene the camera is constantly rotating down. I can fight it by sliding the mouse up(or add to it by sliding the mouse down), but I can't figure out what's causing it.

    I can't seem to find anyone else with this problem, but this feels like a glitch. Any thoughts?

    Here's my code, just in case:
    Code (CSharp):
    1. public Transform playerBody;
    2.     public float xSpeed = 100f;
    3.     public float ySpeed = 100f;
    4.     public bool invxAxis = false;
    5.  
    6.     private float yRotation = 0.0f;
    7.     private float xRotation = 0.0f;
    8.  
    9.     void Start()
    10.     {
    11.  
    12.         Cursor.lockState = CursorLockMode.Locked;
    13.  
    14.     }
    15.  
    16.     void Update()
    17.     {
    18.  
    19.         float mouseY = Input.GetAxis("Mouse Y") * xSpeed * Time.deltaTime;
    20.         float mouseX = Input.GetAxis("Mouse X") * ySpeed * Time.deltaTime;
    21.  
    22.         if (invxAxis == true)
    23.         {
    24.             xRotation += mouseY;
    25.         }
    26.         else
    27.         {
    28.             xRotation -= mouseY;
    29.         }
    30.  
    31.         yRotation += mouseX;
    32.  
    33.         xRotation = Mathf.Clamp(xRotation, -80f, 80f);
    34.  
    35.         //yRotation += mouseX;
    36.  
    37.         playerBody.localRotation = Quaternion.Euler(xRotation, yRotation, 0f);
    38.  
    39.     }
    40. }
     
  2. jukka_j

    jukka_j

    Unity Technologies

    Joined:
    May 4, 2018
    Posts:
    944
    What are the actual values that you see in mouseX and mouseY? When mouse is not moving, do they came out as zero?
     
  3. unity_fqlyjbgDafPWCw

    unity_fqlyjbgDafPWCw

    Joined:
    Feb 5, 2021
    Posts:
    9
    Update: the problem seems to have solved itself.

    Since there was nothing wrong with the version in the engine itself, I moved on until I could get help from here. recently -- despite not working on any of the scripts involving camera movement -- my builds have stopped giving me this issue. Fingers crossed it doesn't come back, but if this was an issue with WebGL or chrome, it seems to have been solved on their end.