How to change the rest position of a PinJoint2d

:bust_in_silhouette: Reply From: thomastc

I took a peek at the source code, assuming you are using Godot 3.

You want _configure_joint to be called, because it recreates the joint object in the physics server, which will use the current position of both bodies to determine the rest position.

_configure_point is called from _update_joint.

_update_joint gets called in several cases:

The latter is probably the most robust way of doing this. Note that the value must actually change for it to work. So you can use this workaround:

pin_joint.disable_collision = !pin_joint.disable_collision
pin_joint.disable_collision = !pin_joint.disable_collision

Removing the node from the tree (remove_child) and adding it again (add_child) should also work, but it can mess with the ordering of nodes so it’s not entirely free of side effects.