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 WASDjump: Space, W or Upaction: 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 * deltaThe 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
EasyMake the hero walk right at 200 pixels per second while you hold move_right. When you let go, the hero stops.
Try it yourself
extends Node2D
func _process(delta):
pass
This lesson includes a short quiz. Start the lesson to answer it and track your progress.
All lessons in Input and Movement
5Project: Platformer Hero
Hero: RunHero: JumpPractice on your own: Godot playground