Custom pivot for a gameobject

Below is a picture depicting “I”, “J”, “L” game objects. Each object has children. These children are blocks and a pivot.
I want to instantiate game objects relative to their child Pivot, but I do not how to do it.

I have a script that instantiates these objects

    public GameObject[] Shapes;
    public Vector2 beginPoint;
    public Vector2 resize;
    public float offsetBetweenBlock;
    private const int numberToShow = 3;
...
for(int i = 0; i < numberToShow; i++)
        {
            GameObject currentShape = Shapes[Random.Range(0, Shapes.Length)];
            Instantiate(
                currentShape,
                new Vector3(beginPoint.x + i * offsetBetweenBlock, beginPoint.y),
                Quaternion.identity,
                transform
                );
        }

But as you can see “J”(Medium) and “L”(Right) are not equal to each other (I pointed at them with red arrows on the picture)

How can I instantiate objects “I”, “J”, “L” with respect to their child Pivot?

Make the “Pivot” be the root parent object and place the children relative to it. If you’re cloning a prefab then create a root pivot object and set the cloned prefab as a child.

2 Likes

Thanks! It is so easy. Sorry for my question

You’re welcome and never be sorry asking questions, it’s the only way we can all learn. :slight_smile:

1 Like