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 += 40This hero takes one 40 pixel step per press. A step is a fixed distance, not a speed, so it has no delta.
Challenge
EasyMake the hero step instead of walk.
- Change both
Input.is_action_pressedtoInput.is_action_just_pressed. - Make each step
40pixels, with nodelta: right formove_right, left formove_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
5Project: Platformer Hero
Hero: RunHero: JumpPractice on your own: Godot playground