I have lockcursor so the cursor doesn't leave the screen, but now i have to rotate an object based on mouse movement (think garrys mod item rotation) but the mouse cursor is obviusly locked to the center, is there anyway of getting the input from the mouse?

 public void GetRotated()
    Debug.Log(Input.GetAxis("Mouse X").ToString() + ", " + Input.GetAxis("Mouse Y").ToString());
    gameObject.transform.localRotation = new Quaternion(Input.GetAxis("Mouse X") * RotationSpeed * Time.deltaTime, Input.GetAxis("Mouse Y") * RotationSpeed * Time.deltaTime, 0, 0);

If you lock it, the mouse won't move at all.

Maybe you can just hide it and you can move the cursor to the center manually after you read the movement info from it.

So, it'll be hidden, it'll stay centered, you'll be able to read the movement.

Does that work for you ?

Notice that this is an operating system specific issue. For example you won't need to lock the cursor on mobile platforms. You may only need it on Windows or on Mac. So, you should make some operating system calls to be able to change the position of the mouse to the center.

On windows you should use this link after adding the required DLLs (System.Windows.Forms.dll and maybe some others required by this dll) into your unity project (btw, I didn't try this by myself) http://msdn.microsoft.com/en-us/library/system.windows.forms.cursor.position.aspx

On mac, the same method should work because Unity runs on Mono framework which is equivalent of Windows .Net framework.

| improve this answer | |
  • \$\begingroup\$ but then the coursor can leave the screen if not in fullscreen \$\endgroup\$ – user2127102 Jul 31 '13 at 16:39
  • \$\begingroup\$ I've edited my answer for more detailed info. \$\endgroup\$ – Xtro Jul 31 '13 at 19:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.