0 votes

Sorry, I'm a hardcore beginner in programming, but I keep having this problem across projects that I can't solve. The problem is having 2 scenes and trying to signal that they enter each other's areas to cause damage or score. In the context of this, I've made a spawner which spawns leaves, the leaves should disappear and give the player a score when they enter the player's area. The code works when both are in the same scene but in my case, only the spawner itself is in the same scene as the player. I have tried using global variables, and instancing the leaves in the player script but I feel like I'm just not understanding and repeatedly getting it wrong. any help is welcomed. thank you!

Godot version 3
in Engine by (21 points)

1 Answer

+2 votes
Best answer

You dont need to connect them to each other. Connect leaves signals to leaves themselves, and You can recognize collision inside the function :

func on_area_enetered(area) :
       if area is Player :
               area.score +=10

there are many methods to recognize collision. iskeyword is for checking classes, meaning if You introduced Player as classname Player. But You can also check for area.name or area.get_parent().name, filename, has_method() and so on.

Advanced sollution for this problem would be to connect all signals within autoloaded script.

by (8,101 points)
selected by
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.