Is there a way to set the mouse position or to restrict the mouse position to a 3D area? We have a static camera so I’m trying to restrict the mouse to a specific 3D area in the scene. It’s not directly top down so the area wouldn’t be rectangular.
My initial idea was to use the ScreenToPointRay and cast a ray using this volume area as the mask and if it doesn’t hit this area it means the mouse tried to go outside the area, but then I would need a way to set the mouse position to the previous frames mouse position make it basically not move.
You may not be able to override the hardware mouse position, but you can certainly turn off the hardware mouse cursor and draw your own instead, at which point you have full control of where it’s drawn and where it’s allowed to move to.
Note that when you restrict movement, you’ll have to account for that restriction in the rest of your input handling too, if that’s appropriate to your game mechanic.
You wouldn’t loose it, but obviously there could be some interaction issues if you’re showing the mouse as being in a different position than Unity thinks it is…