Godot on signal trigger external animation
31. Květen 2024 v 01:14
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:
The player animations:
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?