Mouse control problem

Updated on February 24, 2017 in  [R] Scripts
Share on Facebook0Tweet about this on Twitter0Share on Google+0Share on Reddit0
6 on February 23, 2017

Hello guys, so I am making a game that looks a bit like the DodgeTheBlocks game and my problem is that I decided to make the player control the way that you control it with the mouse. It works perfectly fine and I m happy with it however if I press escape, the pause menu appear and if I click on the left (or right) of the “continue” button, then when I want the player to go all the way to the left (or right) the mouse get blocked on the edge of the screen and so you just can’t finish the level..
So now that I ve explained you my issue my idea was to either make the mouse be able to go out of the screen, however idk if that is possible. Or if there is any ways I can make the mouse spawn in the middle of the screen each time the “continue” button is pressed. Thank you very much :)

  • Liked by
Reply
2 on February 23, 2017

Have you added a mouse lock already? So it hides and lock the screen when you’re not on the pause menu and it unlocks it again when you’re on the pause menu.

on February 24, 2017

Well I did and it works perfectly fine for to make it disappear but the problem is that basically the player kind a follow the mouse and if I exit the pause menu with the mouse not centered on my screen then the player cant go all the way to one side because it get blocked on the side of the screen. It also happen when I start the game with the mouse not centered…
I m just wondering if there is a way to make it so the mouse position keep increasing or decreasing even if it s further than the edge of the screen.

on February 24, 2017

How about trying to resetting the mouse position to the center every time you exit the pause menu?
There’s a command to lock and confine the mouse, you should search for it.

Show more replies
  • Liked by
Reply
Cancel
2 on February 24, 2017

Sounds like you have been hiding the cursor, but not locking it?

“When locked, the cursor will automatically be centered on view and made to never leave the view. The cursor will be invisible in this state, regardless of the value of Cursor.visible.”
When in the state “confined” though, it will then become visible (I think).

So, if you just need to center your cursor again, I think you could be able to do it in two lines:

Cursor.lockState = CursorLockMode.locked;  //makes it invisible and centers it to screen
Cursor.lockState = CursorLockMode.none;  //makes it visible without restrictions

Now, I haven’t tried it so I can’t verify, but it’s my first hunch.
 
Here’s the manual on Cursor.lockState and CursorLockMode.

on February 24, 2017

That’s what I’m talking about. If it’s confined the cursor behaves normally with the exception of being confined to the view.

on February 24, 2017

Ok thank you so much for taking time for my problem, I m gonna check that out and let you know :)

Show more replies
  • Liked by
Reply
Cancel