I have a player scene that can move and shoot a bullet. But when I instance the player in another scene, the shooting behavior no longer works.
The bullet has a sprite, a CollisionShape2D, and a very simple script that manages its movement. The player script includes the following code that manages the bullet ("Shootport1" is a Position2D child object of Player):
export(PackedScene) var Bullet = load("res://Combat/Bullet.tscn")
func bshoot():
var b = Bullet.instance()
get_tree().root.get_child(0).add_child(b)
b.position = $Shootport1.position
When I play the "player" scene, the bullet spawns and moves just fine. But I have a "template" scene that has a player child object, and the player moves but does not shoot.
There's no script attached to the template scene. I tried adding a script that loads Bullet.tscn, but that didn't change anything. Currently, the template scene has nothing but the child player node.
I also tried replacing get_tree().root.get_child(0)
with owner
, with no luck there either.
My best guess is that there is something at work in Godot's scene tree that I don't understand yet. I'm very new to this.