I'm working on a 2d shooter and want to add upgrade pods to my ship. I want 3 positions around the ship for upgrade pods. So I've added 3 Position2D nodes to my Player (the ship). I started off by instancing a child pod to the ship at the position of the Position 2D nodes. This works fine. Oh, and by the way, I put the Pos2D's in a plain old Node (container) to keep things tidy.
var w = upgrade_pod.instance()
add_child(w)
w.position = $upgrade_pod_container.get_node("Position2D").position
I then figured what happens if I have all 3 places filled or say position 2 pod gets destroyed. I want to stop adding pods if there are no free spaces or add a new pod to the next available space.
I thought if I instance the pod as a child of the Pos2D, I could check if the Pos2D had a child before trying to add a new one.
This code runs (i.e. doesn't crash) but the new pod is always added at the top left corner of the screen. I can see it as a child of the Pos2D in the 'tree', but it no longer follows and orients to the overall parent, Player (the ship).
var w = upgrade_pod.instance()
$upgrade_pod_container.get_node("Position2D").add_child(w)
w.position = $upgrade_pod_container.get_node("Position2D").position
Same result if I omit the 3rd line of code
Why doesn't it work? and how do I make it work?