FreshRSS

Zobrazení pro čtení

Jsou dostupné nové články, klikněte pro obnovení stránky.

Godot on signal trigger external animation

It may not matter, but I'm following How to make a Video Game - Godot Beginner Tutorial. I want to implement the dying animation instead of removing CollisionShape2D from the body (parameter passed to Area2D's _on_body_entered signal).

The player:

enter image description here

The player animations:

enter image description here

The code to remove the CollisionShape2D (player falls off the screen before restarting, based on tutorial) that works:

func _on_body_entered(body):
    print("You die")
    Engine.time_scale = 0.5
    body.get_node("CollisionShape2D").queue_free()
    timer.start()

What I've tried to get dying animation to play:

func _on_body_entered(body):
    print("You die")
    var player_anim = body.get_node("AnimatedSprite2D") # tried a single line as well
    Engine.time_scale = 0.5
    player_anim.play("dying" )
    timer.start()

I get no errors, it just resets after the designated amount of time. Is it possible to trigger player dying animation from Area2D script?

❌