How would you randomly generate game objects a set distance from the player, but anywhere along that circle’s edge?
Suppose you have a 2D defense game where you’re immobile in the center and want enemies/hazards to appear from offscreen in every direction - ideally facing generally toward the player so that they can be fed forward momentum to come rolling onscreen.
Is there a way to generate game objects at the border of a sphere collider?
Vector2 GetRandomPointOnCircle(float radius)
{
float angle = Random.value * Mathf.PI * 2;
float x = Mathf.Cos(angle) * radius;
float y = Mathf.Sin(angle) * radius;
return new Vector2(x, y);
}