0 votes

Hey there,

I have to deploy a little program for university.
I have an enemy(bird) and collecting items(apples).
What I want is:
If the bird die the apples should disappear.

Do you have any idea how to do so ?

in Engine by (12 points)

1 Answer

0 votes

If I understand your question correctly, you have a bird (kinematic body 2d) collecting apples (area 2ds) and you want all the apples to disapear when the bird dies.

To keep things simple, add an autoload script to your project and call it PlayerInfo (or whatever you like). Declare a signal inside that script:

signal player_died 

Now, inside the bird script, when the bird is just about to die (before you call queue_free()) emit the signal:


Finally catch that signal inside the apple script.
First connect the signal inside the _ready() function:

PlayerInfo.connect("player_died", self, "_on_player_died")

Then declare the _on_player_died() function:

func _on_player_died() -> void:
    queue_free() // if you want to kill the apple or
    hide() // if if you just want to hide it
by (2,017 points)

Hmm doesn't work. If the bird dies I got the error:
Invalid call. Nonexistent function 'emit' in base 'Node(PlayerInfor.gd)'.
You know why ?

It works ! I had to change the emit into emit_signal()

Thank you so much for your help!

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.