In my WebGL Project here is the way for camera navigation (Movement/Rotation) on Update event:

void UpdateMovement()

        bool accelerate = Input.GetKey(KeyCode.LeftShift) || Input.GetKey(KeyCode.RightShift);
        moveDirection   = 
                Input.GetAxisRaw("Horizontal") * moveSpeed, 
            Input.GetAxisRaw("Vertical") * moveSpeed);
        //moveDirection = new Vector3(Input.GetAxis("Horizontal") * moveSpeed, 0, Input.GetAxis("Vertical") * moveSpeed);
        moveDirection   = transform.TransformDirection(moveDirection);

        if (Input.GetButton("Up"))
            moveDirection.y += moveSpeed;
        else if (Input.GetButton("Down"))
            moveDirection.y -= moveSpeed;

        if (Input.GetAxisRaw("Mouse ScrollWheel") > 0)
            moveDirection.y = moveDirection.y + scrollSpeed;
        else if (Input.GetAxisRaw("Mouse ScrollWheel") < 0)
            moveDirection.y = moveDirection.y - scrollSpeed;

       moveDirection *= (accelerate ? speed : moveSpeed);
        controller.Move(moveDirection * Time.deltaTime);

    void UpdateRotation()
        if (!Input.GetMouseButton(1))

        rotationX += Input.GetAxis("Mouse X") * lookSpeed;
        rotationY += Input.GetAxis("Mouse Y") * lookSpeed;
        rotationY = Mathf.Clamp(rotationY, -90, 90);
        rotationZ = Input.GetAxis("Mouse ScrollWheel");

        transform.localRotation = Quaternion.AngleAxis(rotationZ, Vector3.forward);
        transform.localRotation = Quaternion.AngleAxis(rotationX, Vector3.up);
        transform.localRotation *= Quaternion.AngleAxis(rotationY, Vector3.left);

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.

 Debug.Log("Hr GetAxisRaw : " + Input.GetAxisRaw("Horizontal"));
 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.

Keyboard input settings

  • \$\begingroup\$ Can you show us exactly what input you logged, where in this code? Since you mention the effect doesn't manifest when you don't rotate the camera, I'd say this line may be suspect: moveDirection = transform.TransformDirection(moveDirection); Is it possible you've rotated the camera such that your forward / side to side movement points partly along the y, making it look like you're still getting input from your vertical movement keys when it's actually coming from your other inputs? \$\endgroup\$ – DMGregory Jun 18 at 11:12
  • \$\begingroup\$ Sorry i forget to mention those details. Both methods are working on Update event. while I have logged Input.GetAxisRaw("Horizontal").It don't get back to zero. It depends on the input axis that which axis i am using while using the mouse. \$\endgroup\$ – Muhammad Faizan Khan Jun 18 at 12:27
  • \$\begingroup\$ I identify that it is the same horizontal or vertical key which is not reset to zero when i release the key. \$\endgroup\$ – Muhammad Faizan Khan Jun 19 at 5:00
  • \$\begingroup\$ I can confirm that i am getting input form get axis (horizontal or vertical) as i have logged its value it is 1 or -1 even after releasing the key. \$\endgroup\$ – Muhammad Faizan Khan Jun 19 at 5:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.