How do you lock the mouse in the middle like minecraft is?

when i move the mouse the game screen moves but the mouse goes like normal and doesnt stay in 1 spot

Cursor.lockState