mrdoob / three.js

JavaScript 3D Library.
https://threejs.org/
MIT License
103.18k stars 35.43k forks source link

PointerLockControl Gets Mouse Skips From Time To Time #27040

Closed kurazl closed 1 year ago

kurazl commented 1 year ago

Description

This issue is seen even on the FPS examples provided by three.js here and here. Every single application of PointerLockControls from established games like https://krunker.io/ to small time FPS examples on Github, I experience this issue as well.

After testing various mouse issue, it seems to have something to do with the polling rate. When my mouse's polling rate is set to 1000, there are instances where the camera "skips" or "teleports" which is unexpected. When my mouse's polling rate is set to 500, this happens but at a much lower rate. When my mouse's polling rate is set to 125, I rarely experience this.

Another factor in testing this was whether I was streaming or not. When I was streaming (I was streaming on Discord), this happened quite frequently. When I stopped streaming, this happened, but less frequently. (Note, previous polling rate experiments were done while streaming.)

Hardware Recreation:

Reproduction steps

  1. Enter PointerLockControl's locked state.
  2. Move mouse around a lot.
  3. From time to time, a random "jump" or "skip" or "teleport" happens.

Code

N/A

Live example

Screenshots

This is not my video, but a video of this in krunker.io: https://youtu.be/oQRS7pAaxIc?t=16

Right at the end of the 16th second, his POV gets "teleported" to a different angle instantaneously. This also happens at the end of the 18th second as well.


Video revolving around fixing this issue seen in krunker (which I've also seen in FPS examples provided by three.js themselves) suggest to lower polling rate:

Reddit post with top comment suggesting to lower polling rate:

This was how I found this connection between polling rate and PointerLockControl jumping.

Version

N/A

Device

Desktop

Browser

Chrome, Edge

OS

Windows

gkjohnson commented 1 year ago

If you can reproduce this consistently I would add logs for things like the mouse movement value or rotation values in this onMouseMove function to see what the source of the "jump" is - that might help determine whether the issue is a browser or device problem or not.

kurazl commented 1 year ago

@gkjohnson Could you give what exactly within that function I should be logging? I am logging this movementX and movementY but I'm not seeing anything abnormal when it comes to these jumps.

gkjohnson commented 1 year ago

Could you give what exactly within that function I should be logging?

You should log the intermediate and final variables that are used to drive the rotation of the camera. If the "jump" is caused by PointerControls you'll see larger "jumps" in values before and after you set the euler rotation, for example.

When my mouse's polling rate is set to 500, this happens but at a much lower rate. When my mouse's polling rate is set to 125, I rarely experience this.

Can you also clarify what this means. How are you changing your mouse settings.

Mugen87 commented 1 year ago

Can you also verify if this happens with latest Firefox?

(wired mouse was not tested, although I do not suspect it would make a difference)

It would be interesting to see if other mice produce the same issue with the same Windows 11 computer.

Mugen87 commented 1 year ago

Closing. Device issues like that can't be fixed on engine level.

chuaml commented 9 months ago

I faced similar issue as well. The PointerLockControl mouse movement sometimes skip/jump/teleport around randomly, happen in Edge, Chrome, and FireFox. In FireFox, it feel more like something is pushing your mouse movement and move to wrong direction with smooth movement instead of teleporting and jumping around.

The issue seems kind of random, sometimes mouse movement will skip and jump around a lot, sometimes less often. But it happens enough to be noticeable.

The only workaround I found is to set the control pointerSpeed to 10 or higher value, which somehow result in much lesser chance (if not zero) on mouse teleporting and jumping around. But we are limited to use the super sensitive and fast mouse movement.