- Home /

# place 8 objects around a target gameObject in a circle ( like a compass )

Hey there !

I'm trying to instantiate 8 different gameobjects around my character, but I don't really know the math behind it, to do it with Sin or Asin.

First I was trying to do a for cycle from 1-8, then tried to convert i to degrees then that back to vectors, but somewhere around I gave up on that try.

```
for (int i = 1; i < 8; i++) {
//Got the degree
float degree = Mathf.Asin(i / 360.0f);
//How to convert it to a vector ?
Vector2 vector = ?;
//Instantiating
Vector3 newPos = new Vector3(vector.x, y, vector.z);
GameObject go = Instantiate(GameObject.CreatePrimitive(PrimitiveType.Cube), newPos, Quaternion.identity);
}
```

Does anyone know the math behind it ?

**Answer** by Bunny83
·
Sep 18, 2015 at 10:53 AM

```
float radius = 1f;
for (int i = 0; i < 8; i++)
{
float angle = i * Mathf.PI*2f / 8;
Vector3 newPos = new Vector3(Mathf.Cos(angle)*radius, y, Mathf.Sin(angle)*radius);
GameObject go = Instantiate(GameObject.CreatePrimitive(PrimitiveType.Cube), newPos, Quaternion.identity);
}
```

First of all all trigonometry functions work with radians and not degree (full circle is 2*PI). Second ASin only covers 180°. Next thing is you started your loop with "1" but ended it on "7" ( "< 8"). That's why you usually start at 0 and go up to 7 which are 8 values.

So all you need is Sin and Cos with equally spaced angles in radians.

A very late thank you for this. Easily adapted to arbitrary numbers of objects, and the results are pretty cool on a variable squad of NavAgents for target position offsets. :)

**Answer** by elButterfingers
·
3 hours ago

im a bit late for this but for anyone struggling with this @Bunny83 pretty much gave me everything i needed but i wrapped it into a pretty function for any amount of objects and from any position in the world.

```
public void instantiateInCircle(GameObject obj, Vector3 location, int howMany)
{
for (int i = 0; i < howMany; i++)
{
float radius = howMany;
float angle = i * Mathf.PI * 2f / radius;
Vector3 newPos = transform.position + (new Vector3(Mathf.Cos(angle) * radius, -2, Mathf.Sin(angle) * radius));
Instantiate(obj, newPos, Quaternion.Euler(0, 0, 0));
}
}
```

full credit to @Bunny83 , math is not my thing. neither is programming hence why i came here in the first place LOL.

### Your answer

### Welcome to Unity Answers

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.

### Follow this Question

### Related Questions

How do I get the 'normal' Sinus? 1 Answer

What's wrong with this algorithm? 2 Answers

What's wrong with this type? 1 Answer

Sorting an array of vectors in javascript 1 Answer

Vector math problem 2 Answers