How do I play a death animation after a collision? (Brackey's Godot Beginner Tutorial)

Godot Version

4.22

Question

Hello,

I’m entirely new to Godot and following Brackey’s “How to make a Video Game - Godot Beginner Tutorial”.
How to make a Video Game - Godot Beginner Tutorial

Instead of having the player body fall through a platform, I want to insert a death animation which I have already inserted the sprite frames for in the AnimatedSprite2D child node under the Player scene. The idle, run and jump animations are accessed through the Player scene script, but the killzone that Brackey introduces is a different scene. I tried replacing the line of code that causes the player to fall through blocks when dying with:

body.get_node.(“AnimatedSprite2D”).play(“death”)

This doesn’t work the same way as the line of code used in the player scene script:

animated_sprite_2d.play(“idle”)

Otherwise, I’m not sure how I’d access the same function used in the Killzone scene in the Player scene with an if statement to trigger the death animation, or how to access the sprite animations from the Killzone scene.

I’m not sure how to go about this. Still very new to all this, so any help is really appreciated!
Thank you.

Killzone scene script:
Screenshot 2024-07-23 212152

Player scene script:
image
image

in the player scene script, add a function called

func die():
       animated_sprite_2d.play("death")

in the killzone script:

func on_body_entered(body):
      if body.has_method("die"):
             body.die()

Another solution would be to have an area2d attached to the player and detect when the killzone body enters that area2d.

This made my player stuck in the air, unable to move! Do I need to put this in a specific place? I’m kinda new to coding.