- Home /
Tracking slow mouse movements
Hi,
I was just wondering if there is a way to track very slow mouse movement on the screen. As I understand it, Input.GetAxis("Mouse X"), etc., returns the speed of the mouse movement, so for a very slow moving mouse it seems to register 0.
I am dragging an object in the X/Y plane on the screen and would like it to change its animation when moving left/right. While this works fine when moving quickly in these directions, it will switch to the idle (no left/right movement) animation momentarily as Input.GetAxis("Mouse X") is returning 0. I know I could probably use the transform.position.y of the object in the condition, but was wondering if there is an alternative for the mouse movement first. My condition for moving left is:
if (Input.GetAxis("Mouse X") < 0)
Thanks
Answer by hathol · May 24, 2012 at 02:31 PM
I would just use Input.mousePosition directly. So something along the lines of
Vector3 lastPos;
void Start()
{
lastPos = Input.mousePosition;
}
void Update()
{
Vector3 deltaPos = Input.mousePosition - lastPos;
float deltaX = deltaPos.x;
// do something
lastPos = Input.mousePosition;
}
Edit: you can use deltaPos*Time.deltaTime to get the mouse speed rather than the moved distance