#Signals and animation trigger

1 messages · Page 1 of 1 (latest)

hasty current
#

Hello devs 👋
I'm new to Godot and I need some help with Signals if possible.

I have a Player scene (with animated_sprite_2d containing several animations), and all my running, idle, and jump animations work fine, no problem.

I have another Spikes scene (with area_2d), and I can respawn the player with the editor's Signals (_on_body_entered) 👌.

I would like to play a “death” animation when I collide with my Spikes. To do this, I created a global node called Events that I autoload via my project settings. It loads fine 👌

Here is my global signal

extends Node

signal player_died

Here is how I use it in my Spikes scene script:

func _on_body_entered(body: Node2D) -> void:
    Events.player_died.emit()

And finally, here is how I use it in my Player script:

@onready var animated_sprite_2d = $AnimatedSprite2D

func _ready() -> void:
    Events.player_died.connect(_on_player_died)
    
func _on_player_died() -> void:
    print(“Dead man”)
    animated_sprite_2d.play(“death”)

My problem is this: when I collide with the spikes, my print displays correctly (so I conclude that my global event is OK), but the animation doesn't play... 🤔
I've already tried playing an animation that works (e.g., “run”), but nothing works.

To conclude, here is the tree structure of my project in the attachment.

I'm open to any ideas or suggestions for debugging this. 🤓

Thank you 🙏

wraith dagger
#

Could it be that, in your _process function, you continually set the player's animation (like to "run" or "idle")? That would override the animation you called in _on_player_died
You could set a boolean "is_dead" to true and only manage the player's inputs if it's false

hasty current
#

Oh good idea, I am gonna try this ⏳