- Home /
How to always have the mouse curser in the center of your game ?
Hey guys im making a first person shooter and i have one problem with my view. At first when i start my game, im good untill i start moving alot and eventually my mouse is no longer in the center of my screen like how i wanted to be some times is on the side or bottom.
I want it so that i have a target in the middle of my screen at all times .
I use the MouseLook Script that comes whith the island demo. Any help would be sweet for i need to fix this to keep advancing.Ty in advance!! =)
Answer by diabloroxx · Nov 16, 2010 at 07:14 PM
Try having a look at the First Person Shooter tutorial /demo : http://unity3d.com/support/resources/tutorials/fpstutorial.html
Then please mark the question as Answered and close the question, unless you have anything else. It is always good to keep the community growing.
Answer by Scribe · Nov 16, 2010 at 07:51 PM
You can use Screen.lockCursor: file:///Applications/Unity/Unity.app/Contents/Documentation/Documentation/ScriptReference/Screen-lockCursor.html
Where do you apply this script?. I don't know how to apply this script from the Documentation. I've applied directly to the different elements of the First Person Controller and I haven't watched that the mouse icon should be centered in the middle of the screen...
use it in the mouse look script that is attached to your first person controller
Im using the exact script that the unity scripting reference provided, in c#, but it doesnt work... any ideas on why? i have no errors or anything
Answer by Sibz9000 · Mar 10, 2019 at 01:51 PM
Locking the cursor
Note: This has a side effect of making the cursor invisible.
Use the following code to lock the cursor to the center of the screen.
Cursor.lockState = CursorLockMode.Locked
This can be ideal when using mouse input for pan/tilt or pitch/yaw type controls, i.e. camera pan/title or spacecraft movements
More info, including different lockstates can be found here: