What does "Mouse X" and "Mouse Y" return in Unity?

12,054

Go into Edit -> Project Settings -> Input and check the settings for the Mouse X / Mouse Y axes.

The Type should be "Mouse movement" by default, which means its "mouse delta"

Use Key / Mouse Button for any kind of buttons, Mouse Movement for mouse delta and scrollwheels, Joystick Axis for analog joystick axes and Window Movement for when the user shakes the window.

https://docs.unity3d.com/Manual/class-InputManager.html

Share:
12,054
Dims
Author by

Dims

Software developer & Machine Learning engineer C/C++/Java/C#/Python/Mathematica/MATLAB/Kotlin/R/PHP/JavaScript/SQL/HTML/ LinkedIn: http://www.linkedin.com/in/dimskraft Telegram: https://t.me/dims12 I prefer fishing rod over fish.

Updated on December 05, 2022

Comments

  • Dims
    Dims over 1 year

    I wrote the following update:

    void Update () {
    
            if( Input.GetMouseButton(0) )
            {
    
                if( !dragging )
                {
                    dragging = true;
    
                    xDragStart = Input.GetAxis("Mouse X");
                    yDragStart = Input.GetAxis("Mouse Y");
                }
    
    
                xDrag = Input.GetAxis("Mouse X");
                yDrag = Input.GetAxis("Mouse Y");
    
                DragValuesText.text = "x = " + xDrag + ", y = " + yDrag;
            }
            else
            {
                if( dragging )
                {
                    dragging = false;
                }
            }
    
    
        }
    

    and made a Text UI to display DragValuesText. After this I found, that returned values are small while I am dragging and turn to zero if I stop the mouse. Looks like they return delta. But how can I be sure?

    In documentation I don't see it is definitely delta. It says it CAN be delta, but how to know or change this fact -- it is not said.

  • Dims
    Dims almost 6 years
    So it is impossible to configure absolute values? What units these deltas are in?
  • Fredrik Widerberg
    Fredrik Widerberg almost 6 years
    Im not sure what unit actually.. If you want to know the absolute changes in pixels i guess you could store Input.mousePosition on mousedown and check difference every frame