I'm using the game to control electronics. I use the following code to determine the location of an object (the location is used to perform calculations that are sent to the electronics)
int centerX = Screen.width/2;
int centerY = Screen.height/2;
Vector3 centerVec = new Vector3(centerX, centerY);
Vector3 diffFromCenter = Input.mousePosition - centerVec;
Ray ray = Camera.main.ScreenPointToRay(centerVec + 0.5F*diffFromCenter);
This is used (along with a raycast to determine the appropriate y
value) to determine the location of the object.
The reason I use 0.5*diffFromCenter
is because of the sensitivity of the movement (as seen in the reaction of the electronics)
The problem with this approach is that it when the (real) cursor reaches the edge of the screen and can't move further, the in-game object won't be able reach the edge of the game window.
The only idea I could come up with to solve this problem is to use code to change settings on the speed of the mouse's movement.
I can't come up with a better solution (and this one would require that I also detect when the cursor leaves the game window to restore the mouse movement speed, because we'll be running experiments and someone might need to tweak things during the experiment...)
Cursor.lockState
toLocked
orConfined
to keep the mouse from exiting the window, and readingInput.GetAxis("MouseX")
(and"MouseY"
respectively) to get the relative change in position of the mouse, which you can then scale and accumulate as you desire? \$\endgroup\$Input.GetAxis
- I've come across this but it seems I misunderstood what it does. reading it again, I think I understand how I can use it. I'll give that a try. Thank you! \$\endgroup\$