Mouse movement working as gamepad

Hi!
How am i able to get mouse movement working as an analog stick on a gamepad ?
I need a value between -1 and 1… I have tried with scale and clamp to get proper results, but i don’t get the right “feeling” when using the mouse.
In my code, i would like to treat it the same way, no matter what kind of input device i use (keys, mouse or gamepad)

public void Roll(InputAction.CallbackContext context)
        {

            m_Roll = context.ReadValue<float>();
            Debug.Log("Roll!:" + m_Roll);

            m_Roll = Mathf.Clamp(m_Roll, -1f, 1f);
        }

I have looked at some code etc. but i didn’t find exactly what i was looking for.

The X and Y position of the mouse from -1 to 1, with 0 being the middle of the screen?

Vector2 mousePosition = new Vector2(
  ((Input.mousePosition.x / Screen.width) * 2) - 1,
  ((Input.mousePosition.y / Screen.height) * 2) - 1
);

I just wrote here - haven’t tested but should work.

Hi,
I Guess something like that could work, but then i need different methods to select between mouse and keyboard.
I thought maybe some “Delta Mouse Movement” could work. But i guess i need to add different methods, depending on the inputs.
actually it might be the best, then i also could have different Roll / Pitch values from the keys, depending on how long they are pressed…

    [System.Serializable]
    public class PointerDataProcessor
    {
        public Vector2 CurrentMousePosition => currentMousePosition;
 
        private InputMap _inputMap;
        private Vector2 currentMousePosition;

        public void Initialize()
        {
            _inputMap = InputSystem_Manager.Map;

            _inputMap.Player.Pointer.Enable();
            _inputMap.Player.Pointer.performed += ctx => currentMousePosition = ctx.ReadValue<Vector2>();
        }
    }

It sounds like you need to normalize your vector.
Normalizing will clamp its values to -1 and 1 like you’re describing.

You can also add this to the specific input or action via the input system by adding a normalize processor to it.

1 Like

Hi!
Wouldn’t that just clamp the value of the screen position? Everything will be (1,1)?

Perhaps I misunderstood your usage.
I have the code above in my project and it is giving accurate input for my rotate function using pointer Delta from the input settings.
I made a static poco class for mine so I can just say “InputSystem_Manager.PointerData.CurrentMousePosition” from anywhere in the project.