How do you spawn multiple prefabs within a certain distance from each other from one spawn point?

Say I have four spawn points, and I want each spawn point to instantiate a random amount of rigidbody prefabs within a certain range of each other. I can currently instantiate one prefab per spawn point, so how would I go about doing this?

You calculate the position for each new instance of an object that you are spawning.

A good practice is also to make a collision check before spawning, just to make sure that no object ends up halfway in a wall or something. Another trick is also to define a radius or area around the spawn point where the objects are allowed to appear. That way, you can avoid a lot of collision checks.

Here’s some code. Not tested in unity, so might include syntax errors, but you get the idea.

Vector3 spawnMidPoint = new Vector3(5,0,10);
int num = Random.Range(3,10);
float radius = 10;
float pi2 = 2*Mathf.PI;
for(int i = 0; i<num; i++)
   Vector3 pos = spawnMidPoint + new Vector3(Mathf.Cos(i*pi2/num)*radius,0,Mathf.Sin(i*pi2/num)*radius)
   Instantiate(prefab, pos, rot);