I have the following block of code to create a rope, one segment at a time:
func add_segment(direction):
var new_segment = Segment.instance()
segments.add_child(new_segment)
var new_segment_path = new_segment.get_path()
new_segment.rotation = direction
# Node a is this node, node b is next node
if length > 0:
var prev_segment = segments.get_child(length-1)
prev_segment.connection.node_b = new_segment_path
new_segment.position = (prev_segment.north_pole.position.rotated(direction) +
prev_segment.position)
else:
host_joint.node_b = new_segment_path
length += 1
Each segment is a RigidBody2D with origin at the bottom of the segment and the north_pole at the top. Using this code causes strange behavior of the segments, and it seems like forces pull on them incorrectly. The joints are PinJoint2D, and node_a is defaulted to the segment it's a child of. Host is a KinematicBody2D. I'm fairly certain the position I set new_segment.position to is correct.
However, when I add each segment to segments (a Node2D child of the rope structure) and connect its joint in the editor, everything behaves normally. Why is this the case?