Core Systems quest

Input Guide. Use Input Map actions and event checks so controls survive remapping and ports.

10-20 min · Godot 4.7

Godot input model

Input System Guide

Learn where Godot separates input events, held-state polling, and action mapping when you are coming from Unity.

Open live playground Use the tabs below as a reference sheet.

Mental model

01 Player presses a device input
02 Input Map translates it into an action name
03 Your script reads the event or current state

One-time action

_input(event)

Use this when the press itself matters: jump, shoot, interact, confirm, pause.

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
gdscript
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
gdscript
func _physics_process(delta):
    if Input.is_action_pressed("move_right"):
        position.x += speed * delta

    if Input.is_action_pressed("sprint"):
        speed = sprint_speed
Unity comparison

_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.

1

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.

2

Use actions in code

gdscript
# 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()
Why Input Map matters

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

Modern approach (Godot 4+)
# 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 * speed

Complete platformer movement

CharacterBody2D platformer
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()
Unity comparison

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

gdscript
# 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

gdscript
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

gdscript
func _input(event):
    if event is InputEventMouseMotion:
        var motion = event.relative

        rotation.y -= motion.x * mouse_sensitivity
        rotation.x -= motion.y * mouse_sensitivity

Controller 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

gdscript
# 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

gdscript
# 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)   # Default

Gamepad detection

gdscript
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")
From Unity

Godot's Input Map unifies keyboard and gamepad. You do not need separate old Input Manager checks for every device.

Tutor Checkpoint

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.

Unity habit

Avoid hardcoded KeyCode-style habits for anything player-facing.

Unreal habit

Think of actions as named gameplay intent, not raw buttons.

Godot habit

Read actions with Input methods and keep movement in physics ticks.

Try this

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.