0 votes

I'm currently trying to create a projectile that will split and go to different direction if it detects a wall in front of it.

Here's what I would like to do:

  1. Once the player presses a button, it will signal the main scene to spawn ( using add_child(projectile) ) a projectile at the player's location.

  2. The projectile will go forward.

  3. if the projectile detects a wall in front of it, it will signal the main scene to create 2 new projectiles (different to current projectile) on its location, both going in a different direction.

The problem lies in 3, as I can't find a way to connect the signal of the created projectile to the main scene. I was able to manually connect the signal of the player to the main scene's script as it was already a child of the scene, but I can't connect the signal of the projectile like the player's signal as it doesn't exist in the main scene until I start the game and press the button.

Long story short, the question is:
Is there a way to connect the signal of the spawned projectile (the node) to the main scene (parent) through a script? If it's impossible / not efficient, is there another way?

Thanks, I hope I elaborated it well enough.

asked May 16 in Engine by jsyune1213 (19 points)

1 Answer

+1 vote
Best answer

You can use connect() to connect the new projectile's signal to the function in the parent::

new_projectile.connect('signal_name', get_parent(), 'some_function')
answered May 16 by kidscancode (4,172 points)
selected May 17 by jsyune1213

Thanks, now I solved it.
I think I was overcomplicating the whole situation .

p.s. I love your videos!

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 How to use this Q&A? before posting your first questions.