How to attach a rigidbody sphere to rope

Hello,
I have created something like a rope with cylinders and hinge joints (works fine). Every cylinder is a rigidbody and my sphere is a rigidbody, too.
Now I want my sphere attach to my last cylinder on collision. For this I have this:

public GameObject sphere;
public GameObject parent;

private void OnCollisionEnter(Collision other)
    {
        if (other.gameObject.CompareTag("Player"))
        {
           sphere.transform.SetParent(other.transform);
        }
    }

This works, but my sphere is only a child for a minimum of time and is not really attached to it. So my sphere is not staying on it.
What can I do, that my sphere is attached to it and does the same movement as the parent?

Maybe someone has an idea.
Thank you

Don’t parent it, add a fixed joint to it. Obviously both the rope and the sphere must have a Rigidbody, and you must set the joint to link to the other RB.

1 Like

@Kurt-Dekker
This works pretty fine, but I can’t get my sphere unattached.

You just Destroy() the connecting joint.

1 Like

Thank you, but how to get the joint?

Just like you get everything else in Unity!!!

  • if it exists from the start of the scene, make a public field and drag the reference in (easiest fastest way)

  • if you make it at runtime, both Instantiate() and AddComponent() will return what they make. Keep that reference.

1 Like

Perfect!