1
\$\begingroup\$

I want to implement a panning system, and people said to me that the cursor should be locked in place during the panning.

However in Unity all I could find is setting the Cursor.lockState to Locked, but that causes the cursor to be snapped to the center of the screen. Which means that everytime the user finishes the pan, the cursor is now in the center of the screen. Which is really bad UX.

It would be all fine if I could just set back the cursor to the position where it was when the pan started. Sadly, as far as I know, Unity doesn't support this. I managed to implement it on Windows by importing user32.dll and then calling SetCursorPos. But I plan to release my game on Mac and Linux too, so I guess even if I could implement this for all supported platforms, this sounds cumbersome and errorprone.

Is there a good crossplatform solution for this problem? Why is it so hard to implement this? If there isn't a cross platform solution, how could I do the same for Mac and Linux?

Thanks in advance!

\$\endgroup\$
1
  • \$\begingroup\$ You could separate where the OS thinks the cursor is from the logical cursor position within your game. Hiding the default cursor and creating your own "game cursor" to drive your click mouse interactions gives you complete control over how it behaves. There's a sample of this approach in this previous Q&A \$\endgroup\$ Commented Jan 26 at 11:20

0

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.