Input systems
Never wire gameplay to raw keys. Map physical inputs (a key, a button, a touch)
to named actions (jump, interact, move), and let gameplay read actions.
That one indirection gives you rebinding, multi-device support, and accessibility
almost for free. This skill is the engine-neutral architecture; bind it to
unity-input-system, unreal-enhanced-input, or Godot's InputMap.
When to use
- Use to design an input layer: actions, bindings, multiple devices, and a
rebinding UI with conflict detection and saved bindings.
- Use to add analog handling (deadzones, sensitivity) and game-feel features
(input buffering, coyote time).
- Use to make controls accessible (full remapping, hold-vs-toggle, sensitivity,
no required simultaneous presses).
When not to use: for an engine's concrete input package/API, use
unity-input-system, unreal-enhanced-input, or Godot's InputMap. For the
movement/jump physics the buffer feeds, see physics-tuning and the engine
movement skill. Persisting bindings to disk is save-systems.
Core workflow
- Define actions, not keys. Gameplay asks "is
jump pressed?", never "is
Space pressed?". Actions are the stable contract; bindings are data.
- Bind per device. Each action holds bindings for keyboard, gamepad, and
touch. The active device is whichever last sent input; swap UI prompts to match.
- Read the right edge. Use pressed-this-frame (edge) for discrete actions
(jump, interact) and held (level) for continuous ones (move, aim). Confusing
the two causes double-fires or missed presses.
- Filter analog input. Apply a deadzone to sticks/triggers so resting drift
reads as zero, and scale sensitivity/curve to taste.
- Buffer for feel. Remember a pressed action for a short window so a slightly
early press still fires (input buffering); allow a jump shortly after leaving a
ledge (coyote time).
- Make rebinding first-class. A UI that captures the next input, detects
conflicts, and persists bindings — and a reset-to-default. Save via
save-systems.
- Verify on every device and with rebinds: keyboard, gamepad, touch; rebind
an action mid-game and confirm gameplay and prompts follow.
Patterns
1. Actions over raw keys; edge vs held
# Gameplay reads ACTIONS. The mapping from key/button to action lives in data.
# Discrete (edge): fire once on the press frame.
if Input.is_action_just_pressed("jump"):
try_jump()
# Continuous (held): read every frame as an axis.
var move := Input.get_axis("move_left", "move_right") # -1..1, one axis
player.velocity.x = move * RUN_SPEED
# Two axes (stick or WASD): get_vector applies a circular deadzone, rescales
# past it and caps the length at 1, so diagonals are not faster.
var dir := Input.get_vector("move_left", "move_right", "move_up", "move_down")
# RIGHT: name actions ("jump"); rebinding/devices just change the binding data.
# WRONG: `if Input.is_key_pressed(KEY_SPACE)` — unrebindable, keyboard-only,
# and `is_key_pressed` is a held check that would re-fire jump every frame.
Engine equivalents (Godot 4.7, Unity 6.3 LTS, Unreal 5.8): Godot InputMap +
Input.is_action_just_pressed (valid in _process and _physics_process);
Unity Input System InputAction / action maps; Unreal Enhanced Input Input Actions + Input Mapping Contexts.
2. Analog deadzone and sensitivity
# Raw sticks never rest at exactly zero. Apply a RADIAL deadzone (on the vector
# length), not per-axis, so diagonals aren't clipped into the axes.
func apply_deadzone(stick: Vector2, dead := 0.2, curve := 1.0) -> Vector2:
var mag := stick.length()
if mag < dead:
return Vector2.ZERO # inside deadzone -> no movement
# Rescale so motion ramps from 0 at the edge of the deadzone, not from `dead`.
var scaled := minf((mag - dead) / (1.0 - dead), 1.0) # some pads report > 1 on diagonals
return stick / mag * pow(scaled, curve) # curve > 1 = finer aim near center
# WRONG: clamping each axis separately — it carves a square hole and snaps to axes.
Keep the response curve (exponent) separate from sensitivity (a plain gain on
the result, usually a camera turn rate) and expose both. Godot's get_vector
already does the deadzone and rescale above, using the average of the four
actions' deadzones (0.2 by default per action) unless you pass one.
3. Input buffering + coyote time (forgiving, responsive feel)
# Buffer: a jump pressed slightly BEFORE landing still triggers on touchdown.
# Coyote: a jump pressed slightly AFTER walking off a ledge still works.
const BUFFER := 0.12 # seconds an early press stays "remembered"
const COYOTE := 0.10 # seconds after leaving ground you can still jump
var _buffer_timer := 0.0
var _coyote_timer := 0.0
func _physics_process(dt):
_buffer_timer -= dt
_coyote_timer = COYOTE if is_on_floor() else _coyote_timer - dt
if Input.is_action_just_pressed("jump"):
_buffer_timer = BUFFER # remember the press
if _buffer_timer > 0.0 and _coyote_timer > 0.0:
velocity.y = JUMP_VELOCITY
_buffer_timer = 0.0; _coyote_timer = 0.0 # consume both so it fires once
4. Rebinding with conflict detection
# Godot 4.7. Capture the next physical input, reject conflicts, then persist.
var _waiting_for: StringName = &"" # set by the "press a key for Jump" button
func _unhandled_input(event: InputEvent) -> void:
if _waiting_for != &"" and _is_bindable(event):
get_viewport().set_input_as_handled()
if not rebind(_waiting_for, event):
show_conflict_warning(event) # offer swap or cancel
_waiting_for = &""
func _is_bindable(e: InputEvent) -> bool:
if e is InputEventKey or e is InputEventJoypadButton or e is InputEventMouseButton:
return e.pressed and not e.is_echo() # ignore releases and key repeat
return e is InputEventJoypadMotion and absf(e.axis_value) > 0.5 # ignore stick noise
func rebind(action: StringName, captured: InputEvent) -> bool:
var event := _to_binding(captured)
for other in InputMap.get_actions():
if other != action and not String(other).begins_with("ui_") \
and InputMap.action_has_event(other, event):
return false # already used -> let UI warn/swap
for old in InputMap.action_get_events(action):
if old.get_class() == event.get_class(): # replace only this device kind's binding
InputMap.action_erase_event(action, old)
InputMap.action_add_event(action, event)
save_bindings() # persist (see save-systems)
return true
func _to_binding(e: InputEvent) -> InputEvent:
if e is InputEventKey: # bind the physical key, not the layout's letter
var k := InputEventKey.new()
k.physical_keycode = e.physical_keycode
return k
var b := e.duplicate() as InputEvent
b.device = -1 # all devices: a pad binding must not stick to pad 0
if b is InputEventJoypadMotion:
b.axis_value = signf(b.axis_value) # keep the direction only
return b
# Compare bindings with action_has_event() / InputEvent.is_match(), never `==`:
# two InputEvents with the same key are different objects, so `==` is false.
# Always provide "reset to defaults" (InputMap.load_from_project_settings()), and
# never let the player unbind a key they need to reach the menu without an alternative.
Keyboard bindings use the physical key (physical_keycode, with keycode
left at 0, which is what makes Godot match by position), so WASD stays in the
same place on AZERTY or Dvorak; show the label for the player's layout with
DisplayServer.keyboard_get_label_from_physical. Unity Input System action.PerformInteractiveRebinding() and
SaveBindingOverridesAsJson() / LoadBindingOverridesFromJson(); Unreal
Enhanced Input User Settings (enable under Project Settings ▸ Enhanced Input)
with player-mappable keys on the mapping context.
Pitfalls
- Hardcoding keys in gameplay blocks rebinding, locks out gamepad/touch, and
scatters input logic. Read named actions only.
- Edge vs held confusion: using a held check for jump re-fires every frame;
using an edge check for movement drops held input. Match the check to the action.
- Per-axis deadzones clip diagonal stick input and snap movement to the axes.
Use a radial deadzone on the vector magnitude.
- No buffering/coyote time makes tight platformers feel unfair even when the
physics are correct — players "clearly pressed jump". Add small windows.
- Rebinding without conflict handling lets two actions share a key, or strands
the player by unbinding menu access. Detect conflicts; guarantee a way back.
- WASD lands in the wrong place on AZERTY/QWERTZ: bindings stored by key
letter follow the layout. Store physical key positions and display the
layout's label.
- A rebound gamepad button works only for player 1: the captured event
carried pad 0's device ID. Store bindings for all devices (Godot
device = -1)
unless the game assigns pads to players on purpose.
- Not swapping prompts on device change shows "Press Space" to a gamepad
player. Track the last-used device and switch glyphs.
- Ignoring accessibility: required simultaneous presses, no remap, fixed
sensitivity, hold-only actions. Offer remap, toggle-vs-hold, and sensitivity.
- Reading input in the wrong loop: poll held state in the physics step for
consistent movement; capture discrete presses so none are missed between frames.
References
references/buffering-and-accessibility.md — buffering/coyote tuning, jump feel
(variable height, apex), device detection and prompt swapping, touch controls,
and an accessibility checklist (remap, toggle/hold, sensitivity, latency).
Related skills
unity-input-system, unreal-enhanced-input — concrete engine input APIs
(Godot uses InputMap + the Input singleton).
save-systems — persist custom key bindings and input settings.
physics-tuning — the movement the buffer/coyote windows feed into.
platformer, fps-shooter — genres whose feel depends on input handling.
1---2name: input-systems3description: >4 Architect game input — action mapping (abstracting keys into named actions),5 rebinding with conflict detection and persistence, multi-device support6 (keyboard, gamepad, touch), analog deadzones, and feel features like input7 buffering and coyote time, plus accessibility. Engine-neutral. Use when the8 user mentions input mapping, rebind controls, gamepad support, deadzone, input9 buffering, coyote time, or accessible controls.10metadata:11 source: https://skillmd.com/skills/junmystery/input-systems12---1314# Input systems1516Never wire gameplay to raw keys. Map physical inputs (a key, a button, a touch)17to named **actions** (`jump`, `interact`, `move`), and let gameplay read actions.18That one indirection gives you rebinding, multi-device support, and accessibility19almost for free. This skill is the engine-neutral architecture; bind it to20`unity-input-system`, `unreal-enhanced-input`, or Godot's `InputMap`.2122## When to use2324- Use to design an input layer: actions, bindings, multiple devices, and a25 rebinding UI with conflict detection and saved bindings.26- Use to add analog handling (deadzones, sensitivity) and game-feel features27 (input buffering, coyote time).28- Use to make controls accessible (full remapping, hold-vs-toggle, sensitivity,29 no required simultaneous presses).3031**When *not* to use:** for an engine's concrete input package/API, use32`unity-input-system`, `unreal-enhanced-input`, or Godot's InputMap. For the33movement/jump *physics* the buffer feeds, see `physics-tuning` and the engine34movement skill. Persisting bindings to disk is `save-systems`.3536## Core workflow37381. **Define actions, not keys.** Gameplay asks "is `jump` pressed?", never "is39 Space pressed?". Actions are the stable contract; bindings are data.402. **Bind per device.** Each action holds bindings for keyboard, gamepad, and41 touch. The active device is whichever last sent input; swap UI prompts to match.423. **Read the right edge.** Use *pressed-this-frame* (edge) for discrete actions43 (jump, interact) and *held* (level) for continuous ones (move, aim). Confusing44 the two causes double-fires or missed presses.454. **Filter analog input.** Apply a deadzone to sticks/triggers so resting drift46 reads as zero, and scale sensitivity/curve to taste.475. **Buffer for feel.** Remember a pressed action for a short window so a slightly48 early press still fires (input buffering); allow a jump shortly after leaving a49 ledge (coyote time).506. **Make rebinding first-class.** A UI that captures the next input, detects51 conflicts, and persists bindings — and a reset-to-default. Save via52 `save-systems`.537. **Verify on every device** and with rebinds: keyboard, gamepad, touch; rebind54 an action mid-game and confirm gameplay and prompts follow.5556## Patterns5758### 1. Actions over raw keys; edge vs held5960```gdscript61# Gameplay reads ACTIONS. The mapping from key/button to action lives in data.62# Discrete (edge): fire once on the press frame.63if Input.is_action_just_pressed("jump"):64 try_jump()65# Continuous (held): read every frame as an axis.66var move := Input.get_axis("move_left", "move_right") # -1..1, one axis67player.velocity.x = move * RUN_SPEED68# Two axes (stick or WASD): get_vector applies a circular deadzone, rescales69# past it and caps the length at 1, so diagonals are not faster.70var dir := Input.get_vector("move_left", "move_right", "move_up", "move_down")71# RIGHT: name actions ("jump"); rebinding/devices just change the binding data.72# WRONG: `if Input.is_key_pressed(KEY_SPACE)` — unrebindable, keyboard-only,73# and `is_key_pressed` is a held check that would re-fire jump every frame.74```7576Engine equivalents (Godot 4.7, Unity 6.3 LTS, Unreal 5.8): Godot `InputMap` +77`Input.is_action_just_pressed` (valid in `_process` and `_physics_process`);78Unity Input System `InputAction` / action maps; Unreal Enhanced Input `Input79Actions` + `Input Mapping Contexts`.8081### 2. Analog deadzone and sensitivity8283```gdscript84# Raw sticks never rest at exactly zero. Apply a RADIAL deadzone (on the vector85# length), not per-axis, so diagonals aren't clipped into the axes.86func apply_deadzone(stick: Vector2, dead := 0.2, curve := 1.0) -> Vector2:87 var mag := stick.length()88 if mag < dead:89 return Vector2.ZERO # inside deadzone -> no movement90 # Rescale so motion ramps from 0 at the edge of the deadzone, not from `dead`.91 var scaled := minf((mag - dead) / (1.0 - dead), 1.0) # some pads report > 1 on diagonals92 return stick / mag * pow(scaled, curve) # curve > 1 = finer aim near center93# WRONG: clamping each axis separately — it carves a square hole and snaps to axes.94```9596Keep the response curve (exponent) separate from sensitivity (a plain gain on97the result, usually a camera turn rate) and expose both. Godot's `get_vector`98already does the deadzone and rescale above, using the average of the four99actions' deadzones (0.2 by default per action) unless you pass one.100101### 3. Input buffering + coyote time (forgiving, responsive feel)102103```gdscript104# Buffer: a jump pressed slightly BEFORE landing still triggers on touchdown.105# Coyote: a jump pressed slightly AFTER walking off a ledge still works.106const BUFFER := 0.12 # seconds an early press stays "remembered"107const COYOTE := 0.10 # seconds after leaving ground you can still jump108var _buffer_timer := 0.0109var _coyote_timer := 0.0110111func _physics_process(dt):112 _buffer_timer -= dt113 _coyote_timer = COYOTE if is_on_floor() else _coyote_timer - dt114 if Input.is_action_just_pressed("jump"):115 _buffer_timer = BUFFER # remember the press116 if _buffer_timer > 0.0 and _coyote_timer > 0.0:117 velocity.y = JUMP_VELOCITY118 _buffer_timer = 0.0; _coyote_timer = 0.0 # consume both so it fires once119```120121### 4. Rebinding with conflict detection122123```gdscript124# Godot 4.7. Capture the next physical input, reject conflicts, then persist.125var _waiting_for: StringName = &"" # set by the "press a key for Jump" button126127func _unhandled_input(event: InputEvent) -> void:128 if _waiting_for != &"" and _is_bindable(event):129 get_viewport().set_input_as_handled()130 if not rebind(_waiting_for, event):131 show_conflict_warning(event) # offer swap or cancel132 _waiting_for = &""133134func _is_bindable(e: InputEvent) -> bool:135 if e is InputEventKey or e is InputEventJoypadButton or e is InputEventMouseButton:136 return e.pressed and not e.is_echo() # ignore releases and key repeat137 return e is InputEventJoypadMotion and absf(e.axis_value) > 0.5 # ignore stick noise138139func rebind(action: StringName, captured: InputEvent) -> bool:140 var event := _to_binding(captured)141 for other in InputMap.get_actions():142 if other != action and not String(other).begins_with("ui_") \143 and InputMap.action_has_event(other, event):144 return false # already used -> let UI warn/swap145 for old in InputMap.action_get_events(action):146 if old.get_class() == event.get_class(): # replace only this device kind's binding147 InputMap.action_erase_event(action, old)148 InputMap.action_add_event(action, event)149 save_bindings() # persist (see save-systems)150 return true151152func _to_binding(e: InputEvent) -> InputEvent:153 if e is InputEventKey: # bind the physical key, not the layout's letter154 var k := InputEventKey.new()155 k.physical_keycode = e.physical_keycode156 return k157 var b := e.duplicate() as InputEvent158 b.device = -1 # all devices: a pad binding must not stick to pad 0159 if b is InputEventJoypadMotion:160 b.axis_value = signf(b.axis_value) # keep the direction only161 return b162# Compare bindings with action_has_event() / InputEvent.is_match(), never `==`:163# two InputEvents with the same key are different objects, so `==` is false.164# Always provide "reset to defaults" (InputMap.load_from_project_settings()), and165# never let the player unbind a key they need to reach the menu without an alternative.166```167168Keyboard bindings use the **physical** key (`physical_keycode`, with `keycode`169left at 0, which is what makes Godot match by position), so WASD stays in the170same place on AZERTY or Dvorak; show the label for the player's layout with171`DisplayServer.keyboard_get_label_from_physical`. Unity Input System `action.PerformInteractiveRebinding()` and172`SaveBindingOverridesAsJson()` / `LoadBindingOverridesFromJson()`; Unreal173Enhanced Input **User Settings** (enable under Project Settings ▸ Enhanced Input)174with player-mappable keys on the mapping context.175176## Pitfalls177178- **Hardcoding keys** in gameplay blocks rebinding, locks out gamepad/touch, and179 scatters input logic. Read named actions only.180- **Edge vs held confusion**: using a held check for jump re-fires every frame;181 using an edge check for movement drops held input. Match the check to the action.182- **Per-axis deadzones** clip diagonal stick input and snap movement to the axes.183 Use a radial deadzone on the vector magnitude.184- **No buffering/coyote time** makes tight platformers feel unfair even when the185 physics are correct — players "clearly pressed jump". Add small windows.186- **Rebinding without conflict handling** lets two actions share a key, or strands187 the player by unbinding menu access. Detect conflicts; guarantee a way back.188- **WASD lands in the wrong place on AZERTY/QWERTZ**: bindings stored by key189 *letter* follow the layout. Store physical key positions and display the190 layout's label.191- **A rebound gamepad button works only for player 1**: the captured event192 carried pad 0's device ID. Store bindings for all devices (Godot `device = -1`)193 unless the game assigns pads to players on purpose.194- **Not swapping prompts on device change** shows "Press Space" to a gamepad195 player. Track the last-used device and switch glyphs.196- **Ignoring accessibility**: required simultaneous presses, no remap, fixed197 sensitivity, hold-only actions. Offer remap, toggle-vs-hold, and sensitivity.198- **Reading input in the wrong loop**: poll held state in the physics step for199 consistent movement; capture discrete presses so none are missed between frames.200201## References202203- `references/buffering-and-accessibility.md` — buffering/coyote tuning, jump feel204 (variable height, apex), device detection and prompt swapping, touch controls,205 and an accessibility checklist (remap, toggle/hold, sensitivity, latency).206207## Related skills208209- `unity-input-system`, `unreal-enhanced-input` — concrete engine input APIs210 (Godot uses `InputMap` + the `Input` singleton).211- `save-systems` — persist custom key bindings and input settings.212- `physics-tuning` — the movement the buffer/coyote windows feed into.213- `platformer`, `fps-shooter` — genres whose feel depends on input handling.