Menu
CoddyTech

Play on a Key

Part of the Game Feel section of Coddy's Godot journey. Lesson 21 of 23.

Your code can start an animation at any moment. Playing a new animation stops the one that was playing and starts the new one from its first key.

func _process(delta):
	if Input.is_action_just_pressed("jump"):
		$AnimationPlayer.play("hop")

"hop" does not loop. It plays once, for 0.6 seconds, and stops at its last key with the robot back on the floor.

The motion is in the animation: the stretch at takeoff, the rise and the fall. The script only decides when it plays.

challenge icon

Challenge

Easy

The robot bobs. Make it hop when you press Space. In _process, when "jump" is just pressed, play "hop".

Try it yourself

extends Node2D

func _ready():
	$AnimationPlayer.play("bob")

func _process(delta):
	pass
quiz iconTest yourself

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

All lessons in Game Feel

Practice on your own: Godot playground