trigger animation on entered Area2D

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By BigBackPack

All I want is to trigger an animation called “dead” on the player after he enters an Area2D.

So I got this code on the Area2D:

extends Area2D
func _on_DeadZone_body_entered(body):
if body.is_in_group(“player”):
body.dead()

And this code on the player:
func dead():
$AnimatedSprite.play(“dead”)
yield($AnimatedSprite, “animation_finished”)
get_tree().change_scene(“res://scenes/screens/GameOverScreen.tscn”)

even though godot is waiting until the animation is finished before loading the next level the animation itself is not playing
I just don’t get this one :smiley:
All I want is to trigger an animation called “dead” on the player after he enters an Area2D.

So I got this code on the Area2D:

extends Area2D
func _on_DeadZone_body_entered(body):
if body.is_in_group(“player”):
body.dead()

And this code on the player:
func dead():
$AnimatedSprite.play(“dead”)
yield($AnimatedSprite, “animation_finished”)
get_tree().change_scene(“res://scenes/screens/GameOverScreen.tscn”)

even though godot is waiting until the animation is finished before loading the next level the animation itself is not playing.
I just don’t get this one :smiley: smb. help please …

When you running game if you press remote and go to player node can you see the amimation change?

Also how does the animation look like?

larrxi | 2020-10-18 07:06

Hey, thx for your questions:

  1. I can not see the animation changed, because the player character is its own scene and the animated sprite node is not the root node of it.

  2. It is a simple dead animation that should be triggered as soon as the character steps into a trap. I also trigger a reload of the scene after the animation is finished, which also works. It is just that the animation itself is not played somehow.

BigBackPack | 2020-10-19 15:27

Yey I got it. :smiley: the problem was that I had a default state which contained an idle animation that overwrote my dead animation. i fixed that with an boolean :smiley: thx for all help

BigBackPack | 2020-10-19 16:12