My question builds off of one of the answers to this question:
https://godotengine.org/qa/23760/how-to-change-the-rest-position-of-a-pinjoint2d
I wanted to update the rest position (i.e. the position where the two objects are attached) of a PinJoint2D on moving one of the objects it's attached to. To do so, I tried out Thomas's answer to the linked question.
Flipping disable_collision
twice didn't affect the rest position, presumably because the value is still the same at the end of the frame being processed. Instead, I tried out calling node.remove_child(joint)
and then node.add_child(joint)
to try and get it to update. This caused the joint to detach entirely. On viewing the node in the debugger at a future frame, I can see that the joint's still a child of the node, and it still has the same node_a
and node_b
paths.
Why would resetting the joint's parental hierarchy cause it to detach, and how can I prevent it? It would make sense if the node no longer had the same relative path to either node_a
or node_b
, but it's been re-parented to the same parent in this case.
Thanks!