Search Unity

nput.GetAxisRaw Key release not working on WebGL

Discussion in 'Web' started by MFKJ, Jun 20, 2019.

  1. MFKJ

    MFKJ

    Joined:
    May 13, 2015
    Posts:
    264
    I am doing camera navigation (Movement/Rotation) on `Update` event in this way:

    Code (CSharp):
    1.     void UpdateMovement()
    2.         {
    3.  
    4.             bool accelerate = Input.GetKey(KeyCode.LeftShift) || Input.GetKey(KeyCode.RightShift);
    5.             moveDirection   =
    6.                 new
    7.                 Vector3(
    8.                     Input.GetAxisRaw("Horizontal") * moveSpeed,
    9.                 0,
    10.                 Input.GetAxisRaw("Vertical") * moveSpeed);
    11.             //moveDirection = new Vector3(Input.GetAxis("Horizontal") * moveSpeed, 0, Input.GetAxis("Vertical") * moveSpeed);
    12.             moveDirection   = transform.TransformDirection(moveDirection);
    13.  
    14.             if (Input.GetButton("Up"))
    15.             {
    16.                 moveDirection.y += moveSpeed;
    17.             }
    18.             else if (Input.GetButton("Down"))
    19.             {
    20.                 moveDirection.y -= moveSpeed;
    21.             }
    22.  
    23.             if (Input.GetAxisRaw("Mouse ScrollWheel") > 0)
    24.             {
    25.                 moveDirection.y = moveDirection.y + scrollSpeed;
    26.             }
    27.             else if (Input.GetAxisRaw("Mouse ScrollWheel") < 0)
    28.             {
    29.                 moveDirection.y = moveDirection.y - scrollSpeed;
    30.             }
    31.  
    32.        
    33.            moveDirection *= (accelerate ? speed : moveSpeed);
    34.             controller.Move(moveDirection * Time.deltaTime);
    35.  
    36.         }
    37.         void UpdateRotation()
    38.         {
    39.             if (!Input.GetMouseButton(1))
    40.                 return;
    41.  
    42.             rotationX += Input.GetAxis("Mouse X") * lookSpeed;
    43.             rotationY += Input.GetAxis("Mouse Y") * lookSpeed;
    44.             rotationY = Mathf.Clamp(rotationY, -90, 90);
    45.             rotationZ = Input.GetAxis("Mouse ScrollWheel");
    46.  
    47.             transform.localRotation = Quaternion.AngleAxis(rotationZ, Vector3.forward);
    48.             transform.localRotation = Quaternion.AngleAxis(rotationX, Vector3.up);
    49.             transform.localRotation *= Quaternion.AngleAxis(rotationY, Vector3.left);
    50.         }
    All working fine but the problem on WebGL canvas when I rotate the camera using mouse and comes out of the bound of WebGl canvas meanwhile, I also continuously press horizontal or vertical key, then release input key doesn't work. Remember I logged the key[`Input.GetAxisRaw("Horizontal")`,`Input.GetAxisRaw("Vertical")`] input and found that it is not reset to zero on release.


    Code (CSharp):
    1.    Debug.Log("Hr GetAxisRaw : " + Input.GetAxisRaw("Horizontal"));
    2.      Debug.Log("Vertical : "     + Input.GetAxisRaw("Vertical"));
    Normally when I don't use camera rotation using mouse and during this time, when i release the horizontal/vertical key, it works fine. I was previously using `Input.GetAxis` now i am using `Input.GetAxisRaw` but the problem is same.
     
    Last edited: Jun 20, 2019
    AdionN likes this.
  2. AdionN

    AdionN

    Joined:
    Nov 6, 2019
    Posts:
    16
    1. I would say this error is the same as I am having, and it seems a lot of people having it. So it will be my small input about it. In your case geting out of bounds dont reset, in my case, button presses are triggered but never returned to 0.
      In webGL only, if you press and hold movement button, and disable character controller script, after enabling it again, the character continues to move, the WebGL saves the state of input axis and it is passed back to script until you press same button again.
      Same bug in New input system and Legacy input systems. Disabling character update function is extremely simple just Enable = false and turning on is just enable = true. This is current test to reset values as in many ways as possible. Unity editor have no problems what so ever.
      if (!_AllowToMove) {
      Input.ResetInputAxes();
      ResetAnimations();
      enabled = _AllowToMove;
      InputSystem.QueueStateEvent(Keyboard.current, default(KeyboardState));
      }
      Vector2 inputVector = inputController.Player.Movement.ReadValue<Vector2>();
      //or in old one
      inputHorizontal = Input.GetAxisRaw("Horizontal");
      inputVertical = Input.GetAxisRaw("Vertical");
      Always gets incorrect value after described events happened. Things that I already tried: - Stop update function from running until Keyboard and mouse is initialized successfully - WebGLInput.captureAllKeyboardInput = true / false - Input.ResetInputAxes(); - InputSystem.QueueStateEvent(Keyboard.current, default(KeyboardState)); - keyboard.anyKey.isPressed disables or resets values manually Problem is that webgl returns button pressed state and Unity cant reset it in anyways....