- Home /
Cursor keeps being moved back to the center of the screen?
I have been trying to solve this for 3 days now and I have been unable to solve it myself. What is happening is when I open my inventory, my mouse is in theory supposed to be shown and unlocked. Now this almost works, except when I try to actually move my mouse around, it almost instantly gets moved straight to the center. I am using Unity version 5.4.0f3.
My code that does this (in the inventory script) is:
if (isShown) { // If the inventory is opened
Cursor.visible = true;
Cursor.lockState = CursorLockMode.None;
}
I have no other code that affects the cursor except for this in a separate script:
if (inventory.isShown || pauseManager.isPaused) { // If inventory is opened or game is paused
Cursor.visible = true;
Cursor.lockState = CursorLockMode.None;
} else {
Cursor.lockState = CursorLockMode.None;
}
Any help would be greatly appreciated ~
Answer by Bunny83 · Oct 06, 2016 at 02:58 AM
Well it soley depend on how you actually lock the cursor. Also what platform do you build for? WebGL for example has some restrictions how the cursor locking works.
Usually when you use CursorLockMode.Locked, just as the documentation says, it will "lock the cursor to the center of the screen".
Maybe you want to use CursorLockMode.Confined? However i'm not sure why it's a problem when the cursor is in the screen center after locking. That's how 90% of all FPS games work (HL, Quake and even Minecraft).
It's not quite clear from your question if you see the cursor elsewhere after unlocking. If that's the case it might be a bug either in the OS or Unity. Again, what platform are you build for? Do you actually test in the editor or in the actual build?
Currently this is all inside the editor and I am on WIndows 10. I need to use CursorLock$$anonymous$$ode.Locked for the purpose of bringing it back to moving the camera around for the purpose of FPS. I have tried confined ins$$anonymous$$d of none, but got a similar issue. I simply lock the cursor. If it makes a difference, I am currently using the Unity Standard Assets FPS controller on my player.
Your answer
![](https://koobas.hobune.stream/wayback/20220612094101im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Turning curser on and off 0 Answers
Cursor Not Centered 0 Answers
Unity Cursor changing back 1 Answer
Cursor not getting centered 0 Answers
cursor visible not working please help 0 Answers