# [Solved] Formation System - Rotate Vector3 Positions around a point?

Hi there,

I’m working on a simple formation system, and thus far I am very pleased with how it turned out.
However, now I would like to rotate all the Vectors around a pivot point, any ideas?

Currently I’m setting all the destinations through Vectors in a list with offsets to the point:

``````private List<Vector3> TwoLineFormation(Vector3 startPoint, float spacing, Vector3 direction)
{
List<Vector3> targetPosList = new List<Vector3>();
int count = selector.getSelectedNPCs().Count;
Debug.Log(count + " NPCs selected");
for (int i = 0; i < 2; i++)
{
for (int x = 0; x <= count / 2; x++)
{
targetPosList.Add(startPoint + new Vector3(spacing / 4, 0, (spacing * x) - (spacing / 2 * count / 2) - spacing / 2));
targetPosList.Add(startPoint + new Vector3(-spacing / 4, 0, (spacing * x + spacing / 2) -(spacing / 2 * count / 2) - spacing / 2));
}
}
return targetPosList;
}
``````

As you see, I would like to use the unused variable direction for that purpose, but I’m quite unsure on how to do that.

To rotate a point around a pivot, subtract the pivot, rotate the result and then add the pivot:

`point = rotation * (point - pivot) + pivot;`

(rotation is a Quaternion, e.g. created with Quaternion.AngleAxis or Quaternion.Euler)

Add the objects you want to pivot around to an empty gameobject with the position you want to pivot around.

For example:
If you want some objects to pivot around (5, 5, 0) with a distance of 4 from the pivot point
Step 1: Create an empty gameobject with the position (0, 0, 0)
Step 2: Make the position of the gameobjects (4, 0, 0) (-4, 0, 0) (0, 4, 0) (0, -4, 0) (These are examples you can change it later)
Step 3: Make the gameobjects children of the empty gameobject.
Step 4: Move the empty gameobject to (5, 5, 0)
For rotation: Rotate the empty gameobject

Not sure if this is what you want but it’s something.

Code for the steps:

``````private void PivotGameObjects(Vector3 pivotPoint, params GameObject[] gameObjects)
{
GameObject pivotObject = new GameObject("PivotObject");
pivotObject.transform.position = pivotPoint;
for (int i = 0; i < gameObjects.Length; i++)
{
gameObjects*.transform.SetParent(pivotObject.transform);*
``````

}
}
Hope the code works didn’t test it.