Menu
CoddyTech

When It Finishes

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

After a hop the robot stands still, because "hop" does not loop. It should go back to bobbing.

An AnimationPlayer sends the animation_finished signal when an animation that does not loop reaches its end. The signal carries the animation's name, so one function can handle every animation.

func _ready():
	$AnimationPlayer.animation_finished.connect(_on_animation_finished)

func _on_animation_finished(anim_name):
	if anim_name == "hop":
		print("Landed")

You connect it the same way as body_entered. A looping animation never ends, so "bob" never sends it.

challenge icon

Challenge

Easy

Make the robot bob again after a hop.

  1. In _ready(), connect $AnimationPlayer.animation_finished to _on_animation_finished.
  2. Write _on_animation_finished(anim_name): when anim_name is "hop", play "bob".

Press Play and press Space: after the hop the robot bobs again. Then Check.

Try it yourself

extends Node2D

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

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

All lessons in Game Feel

Practice on your own: Godot playground