The below code works for some moves but in some point the "new_empty" becomes null and balls stop change position with mouse click.
for pos in all_positions():
if pos.get_meta("occupied") == false:
empty_pos = get_position2d(node.global_position)
if "Red" in pos.name:
elif "Blue" in pos.name:
elif "Green" in pos.name:
elif "Center" in pos.name:
node.global_position = pos.global_position
func reparenting(child, new_parent):
var old_parent = child.get_parent()
var pos = child.global_position
child.global_position = pos
for i in range(all_positions().size()):
if pos == all_positions()[i].global_position:
pos2d = all_positions()[i]
I cannot find why this position became null. I'm using position2d to place the balls which aren't move, but I have 2 platforms which rotated on mouse click 45 degrees. At first I had all positions in MainScene, but I had problems with reparent and the order of nodes(sometimes balls were bellow the platforms), so I have now 8 positions in the one platform, 8 in the other and 9 in the MainScene.
After this change all balls are and go to the correct empty(1 at a time) position2d position. But after some moves the empty position become null. How to debug this to find how this position becomes null? All positions are static and the balls spawned to these positions in _ready.