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
EasyMake the robot bob again after a hop.
- In
_ready(), connect$AnimationPlayer.animation_finishedto_on_animation_finished. - Write
_on_animation_finished(anim_name): whenanim_nameis"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