Dynamically reposition PinJoint2D best practices

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

I’ve been trying to figure out a good solution to this conundrum for weeks now, so it’s time to ask a question.

I have a simulation where the player can pick up a RigidBody2D and fling it across the screen. I have found that I get the most realistic flinging simulation when I use a nested structure of rigid bodies and a pin joint.

RigidBody2D Object
– Pickable “Handle” RigidBody2D
– PinJoint2D

What happens is that I pause the simulation on the “handle”,and have it follow my mouse position. The parent body attached with the pin joint, having never paused its physics simulation, is free to bash into other stuff and react “realistically” rather than simply going inert.

I would like to change the pivot point dynamically by changing the position of the pin joint. Imagine picking up your smartphone from the table by the corner: gravity should make it settle down around the center of rotation where you’re grabbing it.

However, when I do this, the parent body freaks the heck out. The simulation goes wild.

I’m almost to the point in my experiments where I’m going to clone the scene with the new center of rotation and re-instantiate it into the parent scene, but something tells me that will still go wonky with the physics.

So, those of you who understand the Godot physics simulation better than me how would you go about dynamically updating the position of a pin joint to change the center of rotation between objects without destroying the simulation?