The Input System provides a flexible and powerful way to handle user input in your game, supporting multiple input methods and complex input combinations.
- 🎮 Multiple Input Methods: Support for keyboard, mouse, and gamepads
- 🔄 Input Mapping: Dynamic action and axis mapping
- 📊 Input States: Track pressed, just pressed, and just released states
- 🎯 Input Contexts: Context-sensitive input handling
- 🔒 Input Locking: Temporarily disable specific inputs
- 📱 Project Settings: Configure through Godot's project settings
Central manager for all input operations:
- Input action mapping
- Input state tracking
- Context management
# Configure through project settings
core_system/input_system/default_context = "gameplay"
core_system/input_system/input_buffer_time = 0.1
core_system/input_system/double_tap_time = 0.3
# Usage example
func _ready() -> void:
var input = CoreSystem.input_manager
# Register input action
input.register_action("attack", {
"keyboard": KEY_SPACE,
"gamepad": JOY_BUTTON_X
})
# Check input state
if input.is_action_just_pressed("attack"):
perform_attack()# Check for input
func _process(delta: float) -> void:
var input = CoreSystem.input_manager
if input.is_action_pressed("move_right"):
move_right()
if input.is_action_just_pressed("jump"):
jump()
if input.is_action_just_released("crouch"):
stand_up()# Register new input action
func setup_controls() -> void:
var input = CoreSystem.input_manager
input.register_action("special_attack", {
"keyboard": KEY_Q,
"gamepad": JOY_BUTTON_Y,
"mouse": MOUSE_BUTTON_RIGHT
})
# Remap existing action
input.remap_action("jump", "keyboard", KEY_SPACE)# Setup input contexts
func setup_input_contexts() -> void:
var input = CoreSystem.input_manager
# Menu context
input.add_context("menu", {
"ui_up": true,
"ui_down": true,
"ui_accept": true,
"ui_cancel": true
})
# Gameplay context
input.add_context("gameplay", {
"move": true,
"jump": true,
"attack": true
})
# Switch context
input.switch_context("menu")-
Input Organization
- Use clear action names
- Group related actions in contexts
- Consider multiple input methods
-
Performance
- Use input buffering for complex combinations
- Clean up unused input mappings
- Optimize input checks in _process
-
User Experience
- Support input remapping
- Provide visual feedback
- Handle input conflicts
register_action(name: String, mappings: Dictionary) -> void: Register new input actionremap_action(action: String, device: String, key: int) -> void: Remap existing actionremove_action(name: String) -> void: Remove input actionis_action_pressed(action: String) -> bool: Check if action is held downis_action_just_pressed(action: String) -> bool: Check if action was just pressedis_action_just_released(action: String) -> bool: Check if action was just releasedadd_context(name: String, actions: Dictionary) -> void: Add input contextremove_context(name: String) -> void: Remove input contextswitch_context(name: String) -> void: Switch active contextlock_action(action: String) -> void: Lock specific actionunlock_action(action: String) -> void: Unlock specific actionget_action_strength(action: String) -> float: Get analog input strength