- Home /
WebGL Cursor Lock not centering
When the game is run in WebGL in browser. Cursor.lockState = CursorLockMode.Locked does not work. It does not want to lock the cursor in the center of the screen. It locks the cursor, but it only locks to the last place the cursor was before being locked. for example: In Firefox, before locking the cursor, a pop up appears in the top left of the screen which says: "Would you like the pointer to be hidden on this site?", if I click "Hide pointer", the cursor will lock to the position of where "Hide pointer" button was. This happens in: Unity 5.2.1f1, Unity 5.2.3.f1, Unity 5.3.5f1, Unity 5.4.0f3
Answer by Bunny83 · Aug 30, 2016 at 11:11 AM
I'm pertty sure that's a limitation of the browser itself and the Lock API. It only allows to lock the cursor in place. Moving the cursor would mean a website could literally control the clients mouse position on screen. This can be a security issue. So they only allow to lock it in place.
There's nothing Unity can do about it if it's a browser / sandbox limitation. Personally i'm glad that a website can't move my cursor around ^^.
The old Unity webplayer was a different story. Since the webplayer itself was a native application it can do anything on the client PC (moving mouse, format hdds ^^). Though there the security was provided by Unity itself. While the webplayer could in theory move the pointer wherever it want, it only allowed to center it on the webplayer context. Direct browser APIs have to be much more restrictive.
Cursor.lockState = CursorLock$$anonymous$$ode.Locked is meant to lock the cursor and center it. like it says here: https://docs.unity3d.com/$$anonymous$$anual/webgl-cursorfullscreen.html why would it not center it in WebGL? how can a person play a FPS game in WebGL if the cursor is not centered on screen?
Huh? The actual position of the hardware mouse position doesn't matter at all.... For an FPS game all you need is the mouse delta movement which you get without any problems.
Have a look at the official $$anonymous$$ouse lock demo for HT$$anonymous$$L5. The circle acts like a virual cursor even though the hardware cursor is locked in place.
An FPS game doesn't have a "cursor". You usually have a crosshair and this isn't drawn at the mouse position but at the screen center.
Your answer
Follow this Question
Related Questions
WebGL Mouse spawn 0 Answers
How to use CursorLockMode in webGL 0 Answers
How to lock cursor in WebGL 1 Answer
Why does my cursor image have artifacts in WebGL? 2 Answers
Mouse won't unlock in WebGL build but does in the editor 1 Answer