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
EasyConnect the AnimationPlayer's animation_finished signal to a function _on_animation_finished(anim_name). When the finished animation is "hop", play "bob" again.
Try it yourself
extends Node2D
func _ready():
$AnimationPlayer.play("bob")
func _process(delta):
if Input.is_action_just_pressed("jump"):
$AnimationPlayer.play("hop")
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