godot icon indicating copy to clipboard operation
godot copied to clipboard

Add `device` parameter to input action methods

Open Carsonthemonkey opened this issue 1 year ago • 0 comments

Implementation of 10852 Also would help with 3555

Currently, using the Input singleton, actions can only be queried for all devices. This is problematic for local multiplayer games, as these rely on processing different inputs for each connected device separately. This PR adds an optional device argument to the following Input methods:

  • is_action_pressed
  • is_action_just_pressed
  • is_action_just_released
  • get_action_raw_strength
  • get_action_strength
  • get_axis
  • get_vector

This allows the user to filter action queries per device. For example,

const DEVICE_ID = 1
if Input.is_action_just_pressed("jump", false, DEVICE_ID):
    jump()

This parameter is optional and placed after existing ones to ensure backwards compatibility. By default the device parameter uses InputMap::ALL_DEVICES to represent the normal behavior of querying all devices.

NOTE: This clashes with DEVICE_ID_EMULATION, in Godot's current state, but is fixed by #97707

Carsonthemonkey avatar Oct 02 '24 03:10 Carsonthemonkey