Hi, I’m trying to use the new InputSystem from now on, but I’m having some troubles with something as simple as the mouse movement.
With the old system, I’d use Vector2(Input.GetAxis("Mouse X"), Input.GetAxis("Mouse Y"))
And I’d get a nice Vector2 that represents the direction the player is moving the mouse, with smooth transitions between -1<>0<>1. Then I could multiply it to modify the sensitivity.
With the new system I’m trying
lookAction.ReadValue<Vector2>()```
The values it returns are all over the place, they are the opposite of "smooth". They vary each frame depending on the last mouse movement. I get it, this can be useful for lots of applications. But I can't make a smooth camera with this imprecise rotation values.
Before I start working on an ugly workaround to simulate the old -1<>0<>1 behaviour, or even unistall this new InputSystem, I'd like to know if there is any simpler approach. Maybe I shouldn't be using "<Mouse>/delta"?
We have a bit of a quirk with mouse delta values in actions where we accumulate them with-in the frame so if you get multiple callbacks in same frame the values will be increasing in magnitude.
If you try getting the last one in the frame directly, e.g.
void OnUpdate()
{
var delta = Mouse.current.delta.ReadValue();
...
}
Nope. The values are virtually the same in my case. Going up and down each frame, not usable for a smooth movement. I suppose the only solution is to make my own function to get the average direction in which the mouse is moving and translate it into a normalized virtual axis.
I don’t know your specific situation, but if you ask operating system like Windows to give you mouse delta, the values will not be only in [-1, 1] range, they can be [-500, 500] if your fps is low and you move mouse pretty fast. You obviously can move your mouse more than 1 pixel per frame
When you call Input.GetAxis(“Mouse X”) the old system basically multiplies operating system data by 0.05f on Windows as described here Mouse Delta Input
If you want something like camera control where positional information is important, e.g. camera should point where mouse ended-up in, then multiplying delta by some constant to achieve sensitivity you want makes sense. Don’t multiply delta by deltatime, because you want accumulated delta of entire movement instead.
If you want mouse to behave something like a virtual gamepad stick, where the exact position of a mouse is ignored and only the matter of movement presence is important, then you could try Mathf.Clamp(Mouse.current.delta.ReadValue().x * sensitivity, -1, 1) (optionally multiple by * Time.deltatime to get units in velocity) and that should give you desired behavior.