Spheres inside a big Sphere

Hi Unity-Comunity,

my first Post here, and I am just beginner with Unity, so sorry, if my Questions are banal or simply, but I can’t find a way.

What I try is to generate a sphere (a bigger one) and inside of it, I won’t to generate small spheres.

Something like that, only in 3D:
2632183--185032--Kreisse.jpg
Practical would it be (as a Bonus) if the Mother sphere would automatically grow up, with more inner spheres (cells).

I want that everything is made by script (C#).

I found a way to set parent, but I can’t position it really inside…

Some hints would be nice.

Here some lines of Code, how far I come…

    void generateMother () {
        Mother = GameObject.CreatePrimitive(PrimitiveType.Sphere);
        Mother.AddComponent <EventListener1>();
        Mother.AddComponent <Mothers_Script>();
        Mother.name = "Mother";
        Mother.GetComponent<MeshRenderer>().material = mother_material;
        Rigidbody MotherRigidBody = Mother.AddComponent<Rigidbody>();
        MotherRigidBody.mass = 1; // Set the GO's mass to 1 via the Rigidbody.

        /*
         * generating single inside
         * cell of mother Object
         */


        Debug.Log(Mother.transform.position);
        GameObject myFirstSingleZell = generateSingleZell ();
        myFirstSingleZell.transform.parent = Mother.transform;
        Debug.Log(Mother.transform.position);
        Debug.Log(myFirstSingleZell.transform.position);

        //generateStartPopulation();
    }
    GameObject generateSingleZell () {
        GameObject singleCell = GameObject.CreatePrimitive(PrimitiveType.Sphere);
        singleCell.name = "Cell";
        singleCell.GetComponent<MeshRenderer>().material = mother_cell_material;
        Rigidbody CellRigidBody = singleCell.AddComponent<Rigidbody>();
        CellRigidBody.mass = 1; // Set the GO's mass to 1 via the Rigidbody.

        singleCell.transform.localScale += new Vector3(-0.5F, -0.5F, -0.5F);

        return singleCell;
    }

Thanks for help :slight_smile:

So, colliders are to be thought of as being ‘solid’. The SphereCollider created when using GameObject.CreatePrimitive(PrimitiveType.Sphere) doesn’t allow things inside it, not the inverse.

You’re going to have to create a much more custom ‘Mother’ to deal with that sort of collision. Maybe a mesh collider that is

1 Like

Maybe to create a Mother sphere with an inside (invers) sphere as surface? Is modeling possible in Unity3D?

No, but if you create a sphere primitive in something like Blender, you can invert the normals… Maybe creating a mesh collider from this model would work?

We’ve done this before, and yes it sort of works. You need to use concave setting for the MeshCollider, and I think we may have had to break the model in 2 hemispheres.

Sorry the stupid question, but I only see a Sphere Collider or a Mash Renderer, but there seems to be no MeshCollider…

Any hint?

I assure you, there’s a mesh collider:

As well as BoxCollider, CapsuleCollider, and SphereCollider.

I found it, thx

I try it now (without a script) with a simple Cube as Mother, because, mesh Collider wants less then 256 segments…
I think I did it like You said, but still didn’t function.

Here my setups from Mother:

If You look in Scene, the starting point are one in other (and Cell is child of Cube):

But when I start, it happen again:

The inner cell move outside…

Maybe I have something to change?

I think the collider obeys the normals, and your cube has normals pointing outside of it, so the sphere doesn’t see that it’s colliding.
Just my thought on the matter.

I’d build up the mesh in blender or similar. Make sure the normals are pointing inwards.

Another option is to implement your own physics solution. This might be more performant.