Hi.
Title pretty much says it all. I’d like to know how fast the mouse is moving, in all the axis as one value. Mouse input returns either x or y axis, but I only need the speed. How can I calculate it?
Thanks,
Luka
Hi.
Title pretty much says it all. I’d like to know how fast the mouse is moving, in all the axis as one value. Mouse input returns either x or y axis, but I only need the speed. How can I calculate it?
Thanks,
Luka
Check my answer Here : Calculating change in mouse position - Questions & Answers - Unity Discussions
This script will Debug the changes in the mouse position between frames when you click or hold the mouse button. These values are stored in delta.x and delta.y :
#pragma strict
public var delta : Vector3 = Vector3.zero;
private var lastPos : Vector3 = Vector3.zero;
function Update()
{
if ( Input.GetMouseButtonDown(0) )
{
lastPos = Input.mousePosition;
}
else if ( Input.GetMouseButton(0) )
{
delta = Input.mousePosition - lastPos;
// Do Stuff here
Debug.Log( "delta X : " + delta.x );
Debug.Log( "delta Y : " + delta.y );
Debug.Log( "delta distance : " + delta.magnitude );
// End do stuff
lastPos = Input.mousePosition;
}
}
you can get the result from the following function, I think that’s why they did not provide anything like “Input.mousePosition.Delta()”
Input.GetAxis("Mouse X");
Input.GetAxis("Mouse Y");