One-time action
Input Guide. Use Input Map actions and event checks so controls survive remapping and ports.
Godot input model
Input System Guide
Learn where Godot separates input events, held-state polling, and action mapping when you are coming from Unity.
Mental model
Held movement
Input.get_vector()
Use this inside physics updates when direction must stay responsive every frame.Device mapping
Input Map
Name the action once, then bind keyboard, mouse, and gamepad without rewriting code.First choice
Events vs Polling
Godot gives you two clean paths: react to an input event when it happens, or poll the current input state each frame. Most games use both.
Event-based: _input()
Called once when the input occurs. Best for:
- Button presses such as jump, shoot, interact
- Menu navigation and confirm/cancel actions
- Any action where the press should fire once
func _input(event):
if event.is_action_pressed("jump"):
jump()
if event.is_action_pressed("shoot"):
fire_bullet()Polling: Input singleton
Checked every frame. Best for:
- Continuous movement
- Held buttons
- Analog stick input
func _physics_process(delta):
if Input.is_action_pressed("move_right"):
position.x += speed * delta
if Input.is_action_pressed("sprint"):
speed = sprint_speed_input() is closest to button-down style
events, while Input.is_action_pressed() feels
closer to Input.GetKey().
Action names
Input Map
Define named actions in Project > Project Settings > Input Map, then read those action names in code. This keeps controls readable, rebinding-friendly, and device-agnostic.
Define actions in Project Settings
Open Project > Project Settings > Input Map.
Add actions like move_left, jump, and shoot.
Bind keys, mouse buttons, or gamepad inputs to each action.
Use actions in code
# Check if action is currently pressed
if Input.is_action_pressed("move_right"):
velocity.x = speed
# Check if action was just pressed this frame
if Input.is_action_just_pressed("jump"):
velocity.y = jump_force
# Check if action was just released
if Input.is_action_just_released("shoot"):
release_charged_shot()One action name can support keyboard, mouse, and gamepad. Your gameplay code stays about intent instead of raw device keys.
Continuous input
Movement Input
For movement, read a direction vector inside physics. Godot can build that vector from four action names and normalize diagonals for you.
Get direction vector
# Get normalized direction from 4 actions
var direction = Input.get_vector(
"move_left", # negative X
"move_right", # positive X
"move_up", # negative Y
"move_down" # positive Y
)
# direction is a Vector2 like (-1, 0), (0.7, 0.7), etc.
velocity = direction * speedComplete platformer movement
extends CharacterBody2D
var speed = 300.0
var jump_force = -400.0
var gravity = ProjectSettings.get_setting("physics/2d/default_gravity")
func _physics_process(delta):
velocity.y += gravity * delta
var direction = Input.get_axis("move_left", "move_right")
velocity.x = direction * speed
if Input.is_action_just_pressed("jump") and is_on_floor():
velocity.y = jump_force
move_and_slide()Input.get_vector() is like combining Input.GetAxisRaw("Horizontal") and Input.GetAxisRaw("Vertical") into one call.
Pointer input
Mouse Input
Mouse input is usually event-based for clicks and motion-based for aiming, camera look, object placement, or UI interactions.
Mouse position
# Get mouse position in viewport
var mouse_pos = get_viewport().get_mouse_position()
# Get mouse position in world (for 2D games)
var world_pos = get_global_mouse_position()
# Make node look at mouse
look_at(get_global_mouse_position())Mouse clicks
func _input(event):
if event is InputEventMouseButton:
if event.button_index == MOUSE_BUTTON_LEFT:
if event.pressed:
print("Left click at ", event.position)
else:
print("Left button released")
if event.button_index == MOUSE_BUTTON_WHEEL_UP:
zoom_in()
if event.button_index == MOUSE_BUTTON_WHEEL_DOWN:
zoom_out()Mouse motion
func _input(event):
if event is InputEventMouseMotion:
var motion = event.relative
rotation.y -= motion.x * mouse_sensitivity
rotation.x -= motion.y * mouse_sensitivityController support
Gamepad Input
Gamepad buttons can use the same Input Map actions as keyboard and mouse. Analog sticks can be read through actions or raw joy axes.
Basic gamepad input
# Gamepad buttons use the same Input Map
if Input.is_action_just_pressed("jump"):
jump() # Works for keyboard AND gamepad
# Get analog stick values
var stick = Vector2(
Input.get_joy_axis(0, JOY_AXIS_LEFT_X),
Input.get_joy_axis(0, JOY_AXIS_LEFT_Y)
)
# Deadzone handling is built into Input Map actions
var direction = Input.get_vector(
"move_left", "move_right",
"move_up", "move_down"
)Gamepad LED color
# Set gamepad LED color on supported controllers
Input.set_joy_led_color(0, Color.RED) # Player damage
Input.set_joy_led_color(0, Color.GREEN) # Player heal
Input.set_joy_led_color(0, Color.BLUE) # DefaultGamepad detection
var gamepads = Input.get_connected_joypads()
print("Connected: ", gamepads.size())
if gamepads.size() > 0:
var name = Input.get_joy_name(0)
print("Gamepad: ", name)
func _ready():
Input.joy_connection_changed.connect(
_on_joy_connection_changed
)
func _on_joy_connection_changed(device, connected):
if connected:
print("Gamepad ", device, " connected")
else:
print("Gamepad ", device, " disconnected")Godot's Input Map unifies keyboard and gamepad. You do not need separate old Input Manager checks for every device.
Lock the pattern in
Before jumping to the next page, turn the idea into one tiny scene or script. That is where the Godot habit sticks.
Avoid hardcoded KeyCode-style habits for anything player-facing.
Think of actions as named gameplay intent, not raw buttons.
Read actions with Input methods and keep movement in physics ticks.
Create actions for move, jump, attack, pause, and interact before writing controller code.
Frequently asked questions
- How do I set up input actions in Godot?
- Go to Project > Project Settings > Input Map. Add named actions like 'jump' or 'move_left', then bind keys, mouse buttons, or gamepad inputs to each action.