- Home /

**closed**Sep 18, 2020 at 06:03 PM by ugurgulser for the following reason:

The question is answered, right answer was accepted

# Rotate Triangles "Correctly" Around The Circle

Hello,

I have a circle and this circle has orbits around it. The orbits' shape is triangle.

My orbit creation code:

```
public void CreateOrbitsAroundCircle(int num, Vector3 point, float radius)
{
for (int i = 0; i < num; i++)
{
/* Distance around the circle */
var radians = 2 * Mathf.PI / num * i;
/* Get the vector direction */
var vertical = Mathf.Sin(radians);
var horizontal = Mathf.Cos(radians);
var spawnDir = new Vector3(horizontal, vertical, 0);
/* Get the spawn position */
var spawnPos = point + spawnDir * radius; // Radius is just the distance away from the point
/* Now spawn */
var newOrbit = Instantiate(orbit, spawnPos, Quaternion.identity, this.transform);
//newOrbit.name = playerName;
/* Rotate the enemy to face towards player */
//enemy.transform.LookAt(point);
/* Adjust height */
//enemy.transform.Translate(new Vector3(0, enemy.transform.localScale.y / 2, 0));
}
}
```

I can add orbits by this code up to 10 orbits.

My question is this: I want to rotate triangles like my circle has spikes! Like this:

How can I do that?

**Answer** by ugurgulser
·
Sep 18, 2020 at 06:02 PM

I just added this code to orbits. It worked well!

```
target = transform.parent.gameObject;
Vector3 dir = target.transform.position - transform.position;
float angle = Mathf.Atan2(dir.y, dir.x) * Mathf.Rad2Deg;
transform.rotation = Quaternion.AngleAxis(angle + 90, Vector3.forward);
```

**Answer** by unity_ek98vnTRplGj8Q
·
Sep 18, 2020 at 03:30 PM

First make sure your triangle prefab is pointing up. This will make it easy to calculate the rotation to apply to the triangle if we already know the rotation of the prefab before we spawn it. Then you just need to calculate the angle to rotate your triangle by depending on where on the circle you are going to place it. You can do that by calculating the angle between the up direction and the direction of your spawn position.

```
var spawnPos = point + spawnDir * radius; // Radius is just the distance away from the point
float rotAngle = Vector3.Angle(Vector3.Up, spawnDir);
if(spawnDir.x < 0) rotAngle *= -1;
Quaternion orbitRotation = Quaternion.Euler(0, 0, rotAngle);
/* Now spawn */
var newOrbit = Instantiate (orbit, spawnPos, orbitRotation, this.transform);
```

Thanks for your reply.

This code works well with one,two,three and six orbits. When it comes four orbits or more. It gets weird. Can you help me?

### 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.