Search Unity

Mouse movement with Input.GetAxis / Input.GetAxisRaw shows erratic behaviour when cursor is locked

Discussion in 'Web' started by kiamvdd, Jan 3, 2020.

  1. kiamvdd

    kiamvdd

    Joined:
    Sep 30, 2016
    Posts:
    16
    Hi, I'm one of the Unity developers working on 3D Aim Trainer, a browser based aim trainer. It's important to us that we can deliver a smooth experience for all of our users. Unfortunately, some of our users have reported erratic mouse movement, making it hard for them to effectively train their aiming skills. We've set up some tests and have managed to reproduce the issue ourselves.

    Issue:

    Input.GetAxis() and Input.GetAxisRaw() will frequently produce incorrect values for both "Mouse X" and "Mouse Y" in WebGL builds when running on lower end systems using mice with a high polling rate (500Hz and up). We have not been able to test whether this issue is unique to WebGL or if it occurs in standalone windows builds as well. The issue occurs only when the cursor is locked and causes the camera controller in our project to randomly rotate several degrees across a single frame, effectively making the camera skip.

    As the setup required to reproduce this issue requires specific hardware and / or a virtual machine, I've also recorded a video showcasing the issue which you can find in the google drive link at the bottom of the post.

    Steps to reproduce:
    1. Visit the sample project page (itch.io) on a lower end system, using a mouse with a high polling rate. Target framerate should be right around 60 or a little below. In our tests we used an Asus Vivobook S15 using an Intel i3-8130U with built in graphics. A virtual machine with a similar setup may work too, though we haven't tested this. As for the mouse, we used a Logitech G900 and a Corsair Ironclaw, both set to 1000Hz.
    2. Press 'P' to lock the cursor and confirm it is locked.
    3. Move the mouse left and right in long smooth motions
    4. If the setup is correct, you should notice occasional skips in the camera movement. The absolute value of Input.GetAxisRaw("Mouse X") is also displayed on the Y axis in the graph along the bottom of the screen, and will show spikes coinciding with these camera skips.

    Notes:
    • The problem seems to be directly linked to polling rates, as the frequency of these skips decreased alongside the polling rate. At 1000Hz the skips were most frequent, with a slight decrease in frequency at 500Hz, and with the issue being all but gone at 250Hz and 125Hz.
    • We noticed the same issue being present in other WebGL games; most notably in krunker.io, one of the leading WebGL-based first person shooters. This seems to indicate it's not unique to our project but rather caused by an external factor.

    Is this an issue specific to Unity / WebGL, or is there something wrong with the way we've implemented this? Can we do something to fix / mitigate this issue in our project? This is affecting a fair amount of our users and we would like to be able to offer them a smooth experience without having to compromise on their polling rate.

    You can check out the source project along with a video showcasing the issue in our trainer here: google drive.
     
    nxtboyIII likes this.
  2. roka

    roka

    Joined:
    Sep 12, 2010
    Posts:
    596
    I have this problem since a long time on my games (fps games).
    I called this "the jump bug", you look around and boom, your crosshair jump a bit without any reason.
    I never reported it because it's really hard to reproduce.

    I just know that this problem have started for me when i have moved on windows 10, i'm not sure if it can be a factor.
     
  3. unity_5MNMGdWPwzVWig

    unity_5MNMGdWPwzVWig

    Joined:
    Mar 29, 2020
    Posts:
    1
    @roka How did you manage to lock the mouse cursor on the crosshair in your webgl games?
     
  4. nxtboyIII

    nxtboyIII

    Joined:
    Jun 4, 2015
    Posts:
    280
    This happens with my games as well and it's really annoying. Players complain about it and I have no idea how to fix it
     
  5. nxtboyIII

    nxtboyIII

    Joined:
    Jun 4, 2015
    Posts:
    280
    Bump
    This actually affects a lot of my players and I regularly get complaints about it
    It's been happening for years and I have no idea how to fix it.
     
  6. nxtboyIII

    nxtboyIII

    Joined:
    Jun 4, 2015
    Posts:
    280
    Note in the demo provided in the original post, it happens more if you turn the sensitivity down to the lowest
     
  7. jukka_j

    jukka_j

    Unity Technologies

    Joined:
    May 4, 2018
    Posts:
    953
    Hey @kiamvdd , not sure if you're still around on the forums.. I wanted to say that your test project is absolutely excellent. Any chance that the sources to this project might still be available? The Google Drive is unfortunately not alive anymore.
     
  8. unityruba

    unityruba

    Unity Technologies

    Joined:
    Nov 6, 2020
    Posts:
    271
    @nxtboyIII what version of unity are you using? I fixed many bugs in mouse movement + cursor lock since 2020, I'm curious where you're seeing the problem?
     
  9. nxtboyIII

    nxtboyIII

    Joined:
    Jun 4, 2015
    Posts:
    280
    I'm in Unity 2021.3.30f1
     
  10. iSeeGreg

    iSeeGreg

    Joined:
    Aug 17, 2020
    Posts:
    1
    I get an issue where the mouse jumps if I start my look near the top or bottom of the canvas. Only on Windows browsers. Mind you, pressing the mouse button is required to look in our app.