Joint2D node moving unexpectedly when constructing via code

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By MrNoob

When I try coding a pendulum object with a PinJoint2D at both ends, the rigid body at one end moves when I connect at as a node of the joint. However, when I build it in the editor, everything works fine.

It happens as soon as I connect the joint, even if the collision objects are disabled.

Not sure what I’m doing wrong here so would really appreciate if someone could explain this. Thanks!

Below is an example image where I created the pendulum in the editor and then went through the steps of reconstructing it via code:

Example image
a = Constructed in the editor
b = Objects placed in the editor, disabled and without gravity. The local positions are exact copies of the editor-built nodes.
c = Gravity applied, first joint attached, but arm-to-circle joint not attached (Thus the circle has fallen slightly in the screenshot).
d = Circle connected to arm, which causes it to move to a new position.
e = Collision shapes enabled, the circle and arm spin out of control.

I’ve attached the source for this example to a thread on Godotforums