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.

  1. Change both Input.is_action_pressed to Input.is_action_just_pressed.
  2. Make each step 40 pixels, with no delta: right for move_right, left for move_left.

Press Play and tap the arrows: the hero takes one 40 pixel step per press, however long you hold. Then Check.

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

All lessons in Input and Movement

Practice on your own: Godot playground