Menu
CoddyTech

Just Pressed

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

Input.is_action_pressed() is true in every frame the key is held. That suits walking. A jump or a shot should happen once per press.

Input.is_action_just_pressed() is true only in the one frame the key goes down. To make it true again, the player lets go and presses again.

func _process(delta):
	if Input.is_action_just_pressed("move_right"):
		position.x += 40

This hero takes one 40 pixel step per press. A step is a fixed distance, not a speed, so it has no delta.

challenge icon

Challenge

Easy

Make the hero step instead of walk. Each press of move_right moves it 40 pixels right, and each press of move_left 40 pixels left. Holding a key longer adds nothing.

Try it yourself

extends Node2D

func _process(delta):
	if Input.is_action_pressed("move_right"):
		position.x += 200 * delta
	if Input.is_action_pressed("move_left"):
		position.x -= 200 * delta
quiz iconTest yourself

This lesson includes a short quiz. Start the lesson to answer it and track your progress.

All lessons in Input and Movement

Practice on your own: Godot playground