This what I’ve done so far.
How can I set the minimum distance between objects?
I want to say that I use Collider for the objects spawned, since I’ve got Trigger on them.
Thank you!
Hi and welcome. First and foremost: please use code tags. It’s the first sticky on this subforum.
I’m not quite sure what you mean by setting a minimum distance between objects, but from your title i assume you want to make sure that your spawn points are at least some distance d apart from each other. You can use Vector3.Distance to calculate the distance between 2 points, which you could then use to make sure that you do not spawn a point if the distance is below some minimum value.
For a more sophisticated approach, you may wanna have a look at the Poisson Disc Sampling algorithm, which is probably exactly what you are looking for. Poisson Disc Sampling allows you to randomly spawn points in some area, but also prevents collision by assuming some radius for these dots. If you adjust that radius according to your minimum distance, this guarantees that your spawn points cannot possibly get too close to each other. This guy makes nice tutorials imho:
If you want something that’s very conceptually simple (probably not the most performant, but if this is just for instantiation that’s probably fine), you could create a temporary “spawner” object with a SphereCollider (with a radius of your minimum distance) in random places, and let the physics simulation space them out as they collide. After a brief period (or a few calls to Physics.Simulate(), they’ll be spaced out and you can replace them all with the real objects.