I am trying to instantiate a Bullet Node in another Scene. I want this because I want to separate the Bullet Scene from any other Scene and only instantiate it in a Scene when a certain Signal occurs. I tried to follow this example:
Unfortunately, it is not possible to use the Node tab to connect Signals because the Scene which emits the Signal does not see the other Scene where it should connect to.
I read that I can do it programmatically, something like this: bullet.connect("shoot", self, "onPlayer_shoot")
But this does not work for me somehow.
This is my Bullet Script from one Scene:
signal shoot(bullet, direction, location)
onready var bullet = load("res://Scenes/Bullet.tscn")
if event is InputEventMouseButton:
if event.button_index == BUTTON_RIGHT and event.pressed:
emit_signal("shoot", bullet, rotation, position)
I want to connect it to a Player Node in another Scene, I tried something like this
in the Player.gd script which doesn't work
onready var bullet = preload("res://Scripts/Battle/Bullet.gd")
bullet.connect("shoot", self, "_on_Player_shoot")
func _on_Player_shoot(bullet, direction, location):
var b = bullet.instance()
b.rotation = direction
b.position = position
b.velocity = b.velocity.rotated(direction)
What do I need to do here to make this work? Is there a better way than doing it programmatically like this?