Hi guys, I have prefabs made from the circle segments like this:

How can I instantiate them in the circle?

Thanks!

Hi guys, I have prefabs made from the circle segments like this:

How can I instantiate them in the circle?

Thanks!

Okey, let’s do this!

I suppose that you have 2 known variables of this problem: the radius of the circle (* radius*) and the needed amount of pieces to complete it (

Knowing that, we can calculate the angle between two adjacent pieces: **angle = 360 / pieceCount**

Having that angle calculated, and knowing the * radius*, we can start instantiating those pieces around a position,

From here, you’ll have to calculate the quaternion from the angle you have, then calculate a direction from the center where the prefab will be instantiated.

Here is an example of working code for this case:

```
void InstantiateCircle ()
{
float angle = 360f / (float)pieceCount;
for (int i = 0; i < pieceCount; i++)
{
Quaternion rotation = Quaternion.AngleAxis(i * angle, Vector3.up);
Vector3 direction = rotation * Vector3.forward;
Vector3 position = centerPos + (direction * radius);
Instantiate(prefab, position, rotation);
}
}
```

I hope this helps!

One way to do it would be like this (in pseudo code):

```
for each segment
instantiate a segment
rotate the segment around the center of the circle by X degrees
increase X degrees by (360 / segment count)
```

If you have, for example, 6 segments, in each iteration of the loop you would increase the X degrees by 60.

You would also instantiate the segments at the edge of the circle. So, if the center of your circle is (0, 0) and radius is 2, you could instantiate the segments at (2, 0).

Hope that helps.