I’m trying to generate a list of random radial directions in order to spawn coins exploding out from a monster after death.

Ideally the directions are evenly spread out while still remaining random as in if there are 2 orbs spawning the directions will be opposite of each other but this isn’t required.

What is important though is that there’s no overlap and this is where I’m having trouble.

The more orbs spawning the more chance I have of getting the same radial direction so I can’t just use randomizer I would need a way to clamp the direction.

If you take 360 / number of coins, then you have the number of degrees to rotate a point around to get directions all facing away from one another.

Knocked this up in notepad++:

```
public List<Vector3> GetRandomRadialDirections(int count)
{
var directions = new List<Vector3>();
if (count == 0)
{
return directions;
}
float deltaAngle = 360f / count;
Vector2 startDirection2D = Random.insideUnitCircle;
Vector3 startDirection = new Vector3(startDirection2D.x, 0, startDirection2D.y); // map to 3d directions
directions.Add(startDirection);
Quaternion axisRotation = Quaternion.AngleAxis(deltaAngle, Vector3.up);
Vector3 direction = startDirection;
for (int i = 1; i < count; i++)
{
direction = axisRotation * direction;
directions.Add(direction);
}
return directions;
}
```

2 Likes