Rigidbody2d moves randomly when attached to Pinjoint2d

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By t o a s t e d

I’m trying to make a game where you use a magnet to drop objects into a container. The issue is when I spawn the next object connected to the magnet, I don’t know if the issue is due to the pin joint or collisions.
Heres a gif so it is easier to understand:

And here is the code for the node that controls instances. Object is what is being spawned.

func instance_next_object():
var instance = duck.instance()
add_child(instance)
pin.node_b = object.get_path()
object.rotation = magnet.rotation
object.global_position = magnet.global_position + Vector2(cos(object.rotation+deg2rad(90))*7, sin(object.rotation+deg2rad(90))*7)

Thanks