Could you explain to me how does move_child() work? I get these errors:
0:00:27:0826 - Index p_pos=10 out of size (data.children.size() + 1=3)
Typ:Błąd
Opis:
Czas: 0:00:27:0826
C Błąd: Index ppos=10 out of size (data.children.size() + 1=3)
C Źródło: scene\main\node.cpp:308
C Funkcja: Node::movechild
0:00:31:0376 - child is not a child of this node.
Typ:Błąd
Opis: child is not a child of this node.
Czas: 0:00:31:0376
C Błąd: Condition ' pchild->data.parent != this ' is true.
C Źródło: scene\main\node.cpp:310
C Funkcja: Node::movechild
My Nodes are organied like this:
Game
-Chests
--Chest1
--Chest2
--Chest3
-Player
And I'm trying to move a specific Chest, not the whole Chests node, through a method called in Game script. I think these errors are because I'm calling movechild() on a Node that is not a direct child. How to fix that? Also, what is the second argument of movechild() referring to? The Z index, or the amount of children within a Node?
extends Node
func _on_PlayerRange_body_entered(body):
var bodypath = body.get_path()
var bodyname = body.name
var bodynode = get_node(bodypath)
print(bodynode.name)
print(bodypath)
if bodyname != "Player":
var playerposition = get_node("Player").position
var bodyposition = bodynode.position
print(bodyposition.y)
print(playerposition.y)
if bodyposition.y > playerposition.y:
move_child(bodynode, 10)
else:
move_child(bodynode, 1)