- Home /
Detect Mouse Movement
Hello guys, i want to recognize the mouse movement (if it went left, or right, or back etc). How can i do that?
Answer by ExTheSea · Apr 29, 2013 at 05:41 PM
Input.GetAxis("Mouse Y") //returns the Y-Axis and
Input.GetAxis("Mouse X") //return the X-Axis value the mouse is currently at
Also this links may help you: http://answers.unity3d.com/questions/10443/how-to-rotate-an-objects-x-y-z-based-on-mouse-move.html
http://answers.unity3d.com/questions/123647/how-to-detect-mouse-movement-as-an-input.html
Hello, thank youm i just want to ask what about back-forth and how can i detect if the mouse has moved more than a specific number of cm :D
The moving more than a specific amount can be solved with this code: http://answers.unity3d.com/questions/28089/mouse-movement-.html what do you mean by back-forth?
In that code mouseThreshold is 0.2 cm? I mean backward and forward :D
From what i know getaxis returns a value between -1 and 1 so no i don't think they are cm. You have to do some conversation and some google search to find out the scale.
The script i linked to with forward- and backward-detection:
var mousexThreshold = 0.2;
var mouseyThreshold = 0.2;
function Update()
{
var mousex : float = Input.GetAxis ("$$anonymous$$ouse X");
var mousey : float = Input.GetAxis ("$$anonymous$$ouse Y");
if (mousex > mousexThreshold)
{
// Code for mouse moving right
}
else if (mousex < -mousexThreshold)
{
// Code for mouse moving left
}
else
{
// Code for mouse standing still
}
if (mousey > mouseyThreshold)
{
// Code for mouse moving forward
}
else if (mousey < -mouseyThreshold)
{
// Code for mouse moving backward
}
else
{
// Code for mouse standing still
}
}
Hope this helps.
Your answer
Follow this Question
Related Questions
Detecting which way my mouse is moving the most 1 Answer
How to detect double and single clicks using javascript? 1 Answer
How do I detect a mouse hover? 1 Answer
moving an object with mouse ( my script is not smooth enough ) 0 Answers
Making my 2d character's arm follow the mouse, scrpit not working, please help :c 1 Answer