Menu
CoddyTech

Press to Move

Part of the Input and Movement section of Coddy's Godot journey. Lesson 1 of 28.

Godot reads keys through input actions: names for what the player wants to do. Every game in this course has these actions:

  • move_left, move_right, move_up, move_down: the arrow keys and WASD
  • jump: Space, W or Up
  • action: E or Enter

Input.is_action_pressed("move_right") is true while the player holds the right arrow or D. Ask it in _process, which runs every frame:

func _process(delta):
	if Input.is_action_pressed("move_right"):
		position.x += 200 * delta

The line under the if starts with two tabs. It runs only in frames where the key is held, so the hero stops when you let go.

challenge icon

Challenge

Easy

Make the hero walk right while you hold a key.

  1. In _process(), replace pass with an if that asks Input.is_action_pressed("move_right").
  2. Inside it, move the hero right at 200 pixels per second, with delta.

Press Play and hold the right arrow: the hero walks right and stops when you let go. Then Check.

Try it yourself

extends Node2D

func _process(delta):
	pass

All lessons in Input and Movement

Practice on your own: Godot playground