0 votes

I have created my main scene with a player and other kinematic bodies2D that disappear when their Area2D is entered.
On another scene of a control node, I created a countdown timer.

I would want to connect the timer and the kinematic bodies so when their Area2D is entered, they don't just disappear but it also adds a bonus time to the countdown (it won't stop it, just adds few more seconds).

I am not sure how to do this to make it work. Should I instance the control-node scene to the main scene? Does it have to be instanced specifically as a child of the kinematic bodies? How to write the function in code? How to connect the nodes and scenes so they react to one another?

I will be really glad for any help, I am really lost.

Godot version v3.3.3
in Engine by (18 points)

1 Answer

0 votes

There's a few approaches that I would recommend:

Using groups. Add the timer to a group called "timer" or whatever you like, and then you can call a function on that timer by using get_tree().call_group("timer", "timersFunction") where timersFunction is the function you've written in the timer's script that adds more time or whatever

Another approach is to use a global event bus, where you have a global autoload singleton that has a bunch of signals, and any node can make it emit those signals, and any other node can connect to those signals. Here's a tutorial on this approach:

by (1,340 points)

Thank You sooo much.
I used the groups and it worked.
I don't know what I would have done without 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.