I want the turret to instantiate a bullet as a child node. Because if I instantiate the original scene where the bullet comes from, the signals (that come from the turret) won’t work.
This is not the way to instantiate unless your plan is to keep duplicating the bullet.
Did you connect the signals through code after instantiating the bullet in your first try?
The turret node will shoot a bullet every 3 seconds
I created a signal like this: signal your_signal
and then I used the inspector to connect the signals.
If you are instantiating the bullet through code, then you also need to connect the signals through code. Something like new_bullet.your_signal.connect(_some_function)
Will try.
Don’t make Bullet
a child of Turret
within the editor or through code. It will introduce problems you don’t need to deal with.
Instantiate a new Bullet through code every time the turret fires, and add it to your level/map object (NOT to Turret
) through code. Copy Turret
’s global_position
and rotation
to your instantiated Bullet
(or assign Turret
’s entire global_transform
to Bullet
if all you care about is position and rotation. That will point your bullet in the direction the turret is firing, and let the bullet act independently of the turret.
Don’t make Bullet a child of Turret within the editor or through code. It will introduce problems you don’t need to deal with.
The docs have a good example of doing this (kinda hidden in an article about “Instancing with signals”)