I’m implementing a simple Player script, and using input actions for controls like this:
So I have a “Look” action that is mapped to both the right stick of a gamepad and the mouse delta.
I then have a very simple script that does the following:
var look = _input.OnFoot.Look.ReadValue<Vector2>();
var lookLeftRight = look.x * _lookSpeed.x;
var lookUpDown = -look.y * _lookSpeed.y;
transform.localRotation *= Quaternion.Euler(0, lookLeftRight, 0);
(note: _input is an object of my InputActions shown above.)
This works. At least for the mouse.
For the gamepad it technically works as well, but it is frame-rate-dependant. I could simply add "
Time.deltaTime" to the look speed, but then my mouse input is frame-rate-dependant.
So I was wondering, can I detect whether the values come from the mouse or not, so I can optionally multiply by
Time.deltaTime?
Thanks!
1 Like
I found that I can use the following:
if (_input.OnFoot.Look.activeControl?.device.description.deviceClass == "Mouse")
{
....
Not sure if this is the best way though. So if anyway has a better suggestion I’d love to know!
3 Likes
After not having much luck figuring out how to get the current device my solution was to simply create a MouseLook action and only set it to Delta [Mouse] under my mouse and keyboard control scheme. Then with the Player Input behaviour set to ‘Send Messages’ I added an OnMouseLook function to my script in addition to the OnLook that I was using for the controller.
public void OnLook(InputValue value)
{
lookX = value.Get<Vector2>().x;
lookY = -value.Get<Vector2>().y;
}
public void OnMouseLook(InputValue value)
{
lookX = value.Get<Vector2>().x * mouseSensitivity;
lookY = -value.Get<Vector2>().y * mouseSensitivity;
}
zeonni
January 11, 2025, 11:56pm
4
I found a good solution: add a deltatime processor for the gamepad
sealed class DeltaTimeScaleVector2Processor : InputProcessor<Vector2>
{
public float x = 1f;
public float y = 1f;
public override Vector2 Process(Vector2 value, InputControl control)
{
value.x *= Time.deltaTime * x;
value.y *= Time.deltaTime * y;
return value;
}
}