mouse delta

Is there a built in way to get the mouse delta? I’m trying to get some rotation of the camera when the right mouse button is down, but currently I’m using something like:

if(Input.GetMouseButton(1))
{
camRotX += Input.GetAxis(“Mouse X”) * 2.0f;
camRotY -= Input.GetAxis(“Mouse Y”) * 2.0f;

Quaternion rot = Quaternion.Euler(camRotY, camRotX, 0);
cameraAnchor.transform.localRotation = rot;
}

which doesn’t work because the first time I do this it snaps the camera to a funky rotation because Input.GetAxis(“Mouse X”) returns the actual mouse position. Ideally I would only be using a mouse delta.

That is how you get the mouse delta, assuming Mouse X and Mouse Y are set to mouse movement in the input manager, and it works fine here. It doesn’t return the actual mouse position (that’s what Input.mousePosition is for).

–Eric

hmm, so why would my rotation go all crazy when I initially press the right mouse button? In Start() I set the camRotX and Y to the game object local rotation with

camRotX = cameraAnchor.transform.localEulerAngles.x;
camRotY = cameraAnchor.transform.localEulerAngles.y;

so the first time I press the right mouse button, those GetAxis() should return 0 if I don’t move my mouse, which should result in not adding anything to camRotX Y so which I set it back it should be the same rotation as the start of the game, but that’s not what’s happening.

Ah, nvm I see. I need to save the opposite x y in the Start(). Thanks!