DragRigidBodies, Mouse Centering and a custom pause menu. They all hate each other.

Hey,

I have the DragRigidBodies script on my FPController that also has MouseLook, and I hate how the mouse moves all over the place so you have to dance with it for awhile to pick something up, so I tried adding screen.lockCursor, which although meant the cursor wouldn’t fly off out of the game window, it wouldn’t stay centered in the screen (to make it easier and simpler to pick stuff up/interact with items with the mouse), you still had to dance with it to get the cursor in the right place. So I tried this loop:

function update (){
Screen.lockCursor = true;
Screen.lockCursor = false;
}

This was a moderately successful (albeit hacky) way to keep the mouse in the exact middle of screen, and both DragRigidBodies and any other ‘OnMouseEnter’ scripts worked great, so I was happy, until I then wrote a Pause Menu script, which has to use

function Start (){
Screen.lockCursor = false;
}

so that the player is free to click stuff. This is a problem because the loop is prioritized (regardless of it’s place in the inspector or what it’s attached to) and will not let the mouse move on the pause menu.

So, after all that, I have just one question. ‘What is the best way to go about making all this compatible?’ I was thinking one of three things, but I have no idea how to implement any of them.

1)Edit the DragRigidBodies and other ‘OnMouseEnter’ scripts so they activate when a GUI reticule/crosshair is over them, sort of like pretending the GUI IS the mouse (This is my preferred choice).

2)Finding some way to keep the mouse restrained to the very center of the screen without the lockCursor function.

3)Making a pause menu that uses key presses or in some way works WITH the constrained mouse, or making the pause menu override the other script.

Thanks everyone, and I’d like to quickly point out that I have literally scoured nearly every forum and answers pages that could be relevant, but most say that the mouse is read-only, and can’t be made to do things. All the pause menu scripts and help pages I found use the mouse to navigate, and searching for things like ‘activate on GUI over’ or ‘GUI to object recognition’ brings up results that discuss how to set up GUI buttons or similar topics.

Thanks,
Matt

P.s Sorry that it’s huge, but I wanted to make sure I made clear my request and exactly what I wanted, as well as making sure people know I have tried everything before posting this. Thanks

I would attempt to solve this problem by a RayCast from the screen center (or where ever the crosshair is) and checking whether or not it hits anything. I’m not sure how well dragging works with raycasts, but you could, possibly, remember which object was hit and then move it with the mouse possibly hidden with Screen.showCursor = false.
Have a look at Unity - Scripting API: Physics.Raycast .