Instantiate randomly in circle

Hi guys…
Anyone who can help please do, I pretty much have the rest of my game code running except for this one thing…


I want to instantiate a gameobject after every 3 seconds in a circle, at random positions on the circle circumference…1 gameobject at a time but not close to the previous instantiated gameobject…


can anyone please help. Its a 2d game

Let’s see. To get a random point on a circle, you could first get a random angle (0-360), then use Mathf.Sin and Cos to make a point on a circle

float angle = Random.Range(0,360);
float angleRad = angle  * Mathf.Deg2Rad;
Vector2 offset = new Vector2(Mathf.Sin(angleRad), Mathf.Cos(angleRad)) * circleRadius;

Now, to include a point that avoids the previous one (but not the older ones), you could remember the last generated angleRad and generate random numbers only around it.

float minAngle = m_previousAngle + minAngleDistance;
float maxAngle = m_previousAngle - minAngleDistance + 360; 
float angle = Random.Range(minAngle, maxAngle);
// do the circle sin/cos calculation here
m_previousAngle = angle;

Prevent the m_previousAngle from reaching some wildly high/low values by always returning it to 0-360 interval, by using Mathf.Repeat or DeltaAngle (can’t tell now how they handle negative numbers)