Keeping balls that stick together together

How do you make rigidbody balls, when they collide, to stick together, even if other things hit them?

Parenting is the best and easiest solution, just make sure that you turn the childs rigidbody into a kinematic rigidbody.
The problem is that if both balls have the same script, both get the collision message, so you need something to decide who’s the master :wink:

something like that:

// C#
// Script / classname: "BallScript"

public BallScript master = null;

void OnCollisionEnter(Collision collision)
    BallScript other = collision.gameObject.Getcomponent<BallScript>();
    if (other != null)
        if (other.master == null)                   // No master yet?
            master = this;                          // Make this one master
            other.master = this;                    // Tell the other
            other.rigidbody.isKinematic = true;
            collision.transform.parent = transform; // make the other a child of this one.
        else                                        // We already have a master
            master = other.master;                  // So we also use the master
            rigidbody.isKinematic = true;           // and make us a child of the master
            transform.parent = master.transform;

Not sure if setting the rigidbody to kinematic is enough. You might need to use Physics.IgnoreCollision to prevent unwanted collisions with the childs. If that’s too compilcated you can also remove the child rigidbodies.