How to determine the maximum and minimum values of Input.GetAxis("Mouse X")?
I'm trying to determine what would be the maximum and minimum values of:
Input.GetAxis("Mouse X")
Input.GetAxis("Mouse Y")
Input.GetAxis("Mouse ScrollWheel")
By observation, I've determined that my mouse's ScrollWheel range of values is exactly (-0.5, 0, 0.5).
On my machine I can write code to capture these values when I move the mouse rapidly, but how can I determine that concretely on a user's machine?
Can I read these values from the system?
The documentation is your friend:
https://docs.unity3d.com/ScriptReference/Input.GetAxis.html
Returns the value of the virtual axis identified by axisName.
The value will be in the range -1...1 for keyboard and joystick input. If the axis is setup to be delta mouse movement, the mouse delta is multiplied by the axis sensitivity and the range is not -1...1.
I moved this question to the help room since you just rejected it a second before I tried to post my answer ^^.
While I agree that the documentation gives some hints about delta values, it's however not clear if it's just a larger range or if it's actually unbounded. Pure negate logic only works on boolean conditions. if it's not in range -1..1 does not imply it's unbounded. It could be 0..1 or -42..42 which all satisfies the condition not being the range -1..1 ^^.
Answer by Bunny83 · Sep 05, 2019 at 08:25 AM
There are no maximum values as those are all delta inputs. If you somehow manage to move your mouse 1 light year in a millisecond (assumed your mouse could still detect this movement) the value would be off the charts. The same is theoritically possible for the scroll wheel as well but since the "notches" of the scroll wheel are usually quite far apart and your update rate is relatively high you usually only ever see one notch movement at a time. However you can't really be sure what value you get for one notch as it depends on the hardware and sometimes even on the mouse settings in the OS.
In general delta values tell you how much the mouse / screll wheel has been moved since the last frame. Of course there are some hard limitations on how large the values can get. AFAIK most APIs and hardware send the relative delta as 16 bit numbers. Though specific hardware might use higher precision. Just as an example windows WM_MOUSEWHEEL message actually encodes the wheel delta in a 16 bit word as a multiple of 120. This allows for a delta of about "+-273 notches" per update. Nobody will be able to rotate the wheel that fast within a few milli seconds and no (common) hardware would be actually able to detect this ^^. Thouse with a mouse like this you might be able to get more than one notch per update and therefore higher delta values.
A lot software just ignores how far the wheel actually moved but they just determine if the delta was positive or negative. Personally I don't like this approach. Since the amount returned by Mouse X or the scrollwheel can vary heavily from device to device it's common to provide a sensitivity setting for the user to adjust.
Why would you ever want to know the maximum of a delta value anyways? If you just want to make sure that a single delta is not above a certain value, you might just clamp the value between certain limits you want for example to prevent cheating by a user who increases his mouse sensitivity in the OS which would allow him to get larger delta values with less actual movement.
Thanks @Bunny83 for the detailed reply. I'm using a wireless mouse on an Android device to control an object and slight movements of the mouse make the object shoot off. I was trying to deter$$anonymous$$e the "range" of mouse movements possible, so that I could "scale them down" and to make the corresponding "acceptable" object movements. I didn't want to hardcode values based on my hardware.
Right, that's why every operating system that handles mouse input and every FPS game has a sensitivity setting that the user can adjust the way he likes it. On many modern mice you can adjust the DPI of the optical sensor which will change the precision and usually the sensitivity as well. Depending on the game I also use very different mouse sensitivity settings. If I play $$anonymous$$ecraft or space engineers I use a moderate sensitivity. If I play Quake I have a high sensitivity (I can almost do a 360° turn with one move. I don't use mouse acceleration).
So it's impossible to get the "right" mouse speed for every possible hardware as what feels right depends on the user. So just provide a sensitivity setting.
Your answer
Follow this Question
Related Questions
Please help me! Correct script) , 0 Answers
Can you help me understand this script 0 Answers
Space Flight Simulator Turning Problems 0 Answers
Input.GetAxis going crazy when I click outside the game window 0 Answers