- Home /
Mouse event build up?
The title describes what it feels and looks like, however, it may or may not be what is happening.
I have a 3d object that is to be rotated by the user with the mouse when they are holding down mouse button 1. It is working, but after you let go, it seems like a bunch of the rotate functions have built up in a queue and it's about 1-2 seconds behind the user input.
So say I right click on the object and move the mouse in a few circles, the object starts rotating accordingly, but when you let go of the button, it keeps going as if it fell behind in executing the rotations and is catching up.
void Update()
{
if (Input.GetMouseButton(1)) {CameraMoveLogic();}
else if (Cursor.lockState==CursorLockMode.Locked)
{
Cursor.lockState=CursorLockMode.Confined; //returns cursor to window
}
else if (Cursor.lockState==CursorLockMode.Confined)
{
Cursor.lockState=CursorLockMode.None; //removes restriction
}
}
protected void CameraMoveLogic()
{
if (Cursor.lockState!=CursorLockMode.Locked) {Cursor.lockState=CursorLockMode.Locked;}
//if I don't do the above, the rotation stops when moving the mouse outside the window
//depoloy rotator
_rotator.transform.parent=_cube;
_rotator.localPosition=Vector3.zero;
_rotator.parent=null;
_rotator.LookAt(transform);
_cube.parent=_rotator;
//rotate it
_rotator.Rotate(new Vector3(1.0f, 0.0f, 0.0f), -Input.GetAxisRaw("Mouse Y")*Speed*Time.deltaTime);
_rotator.Rotate(new Vector3(0.0f, 1.0f, 0.0f), -Input.GetAxisRaw("Mouse X")*Speed*Time.deltaTime);
//put transforms back the way they were
_cube.parent=null;
_rotator.parent=transform;
}
Yes, regular GetAxis behaves the same way, I just forgot to switch back after seeing if GetAxisRaw made a visible difference.
Any help is much appreciated!
I've found this still happens if I orbit the camera ins$$anonymous$$d of rotating the object. I just commented out the Cursor.lockstate lines and the problem is gone, but the rotation stops once the mouse hits the border of the window or side of the screen depending on if full screen or windowed. Is there away to continue to get the mouse movement even when the cursor is at the border?