Topic was automatically imported from the old Question2Answer platform.
Asked By
Alena
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.
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: https://www.gdquest.com/docs/guidelines/best-practices/godot-gdscript/event-bus/
Thank You sooo much.
I used the groups and it worked.
I don’t know what I would have done without your help.