Author Topic: Mouse cursor resetting to center screen on move?  (Read 7361 times)

BlueSin

  • Newbie
  • *
  • Thank You
  • -Given: 1
  • -Receive: 0
  • Posts: 17
    • View Profile
Mouse cursor resetting to center screen on move?
« on: March 07, 2016, 01:39:07 AM »
I am implementing WASD movement across my 2D tile maps using the built in Horizontal and Vertical axes in Unity.  When I start pressing those keys though the mouse cursor jumps back to the center of the screen, if I try to move the mouse cursor around while using WASD the cursor just keeps resetting to the center of the screen every few frames.  I know this is caused by NGUI because if I disable the UIRoot object in my scene it stops doing it.  Traversing the map works fine, it is just annoying that the cursor jumps to the center of the screen, and will be problematic later given the way I intend to design my game.

Is there a setting somewhere to change this behavior?

devomage

  • Sr. Member
  • ****
  • Thank You
  • -Given: 7
  • -Receive: 67
  • Posts: 250
    • View Profile
Re: Mouse cursor resetting to center screen on move?
« Reply #1 on: March 07, 2016, 06:29:28 AM »
1.  Find your GUI Camera and toggle "Auto Hide Cursor" in the inspector.

2.  Try commenting out anything that has to do with "Screen" or "Cursor" class within UICamera (around line #545).

3.  This thread randomly appears often!  A thorn rather than a bug...  very annoying indeed.

Dune

  • Newbie
  • *
  • Thank You
  • -Given: 1
  • -Receive: 0
  • Posts: 16
    • View Profile
Re: Mouse cursor resetting to center screen on move?
« Reply #2 on: October 21, 2016, 04:15:45 AM »
I tried this, but then my OnClick events stopped working.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Mouse cursor resetting to center screen on move?
« Reply #3 on: October 24, 2016, 06:49:28 AM »
UICamera.autoHideCursor is all that's needed to be turned off (and as devomage pointed out it can be done via inspector). There is no need to edit code.

Dune

  • Newbie
  • *
  • Thank You
  • -Given: 1
  • -Receive: 0
  • Posts: 16
    • View Profile
Re: Mouse cursor resetting to center screen on move?
« Reply #4 on: October 28, 2016, 01:34:54 AM »
With "Auto Hide Cursor" on or off, pressing any movement (WASD) and the cursor appears / disappears for no apparent reason. Making movement jerky. And the cursor is warped to the center of the screen.

Any ideas to what could be causing it?

I've disabled my player controller, to be sure it isn't my code.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Mouse cursor resetting to center screen on move?
« Reply #5 on: October 30, 2016, 12:16:23 PM »
Turn off your controller input on the UICamera. I'm guessing you have some movement axes bound to WASD which are also specified on the UICamera as navigation axes.

Shifty Geezer

  • Full Member
  • ***
  • Thank You
  • -Given: 7
  • -Receive: 9
  • Posts: 226
    • View Profile
Re: Mouse cursor resetting to center screen on move?
« Reply #6 on: July 08, 2017, 11:22:36 AM »
I'm experiencing the same issue using mouse game. Only using the mouse for input (emulating touches - the game is aimed at touch screens), sometimes when playing in the editor the mouse decides to keep being centred at fractional second intervals; it's not every frame judging by the distance the pointer moves. I had it just now where it kept doing this every run, and restarted Unity where the problem was fixed (other than the sporadic issue always faced). I have a PS3 controller attached via USB which might be involved? I'm guessing it's something like that because restarting Unity eased the problem, but it's not consistent.

Next time I'll try disabling the controller in UI camera. However they should be able to operate side-by-side.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Mouse cursor resetting to center screen on move?
« Reply #7 on: July 15, 2017, 06:02:30 AM »
They do operate side by side, but activating one hides the other -- otherwise you would have two things selected at the same time (hovering mouse + controller-selected object). Sounds like your controller was reporting non-zero values that were caught by the UICamera because the axes used were specified on it. This can also be resolved by increasing the dead zone of your controller input.