Question by
juanpaco · Apr 07 at 05:59 PM ·
quaternionrandom
Prevent overlap with Random.onUnitSphere
I'm creating a sphere primitive, with n smaller spheres placed randomly on the surface.
After creating the smaller spheres and parenting to the larger sphere, I'm using Random.onUnitSphere * parentSphereRadius
to position them correctly. The problem is that I want to prevent the spheres from overlapping.
Since onUnitSphere returns a Vector3, I was trying to create a while loop if Vector3.Distance was below a certain threshold, but can't figure out how to get it to work. What's the best way to solve a problem like this? Here's a 2d cutaway of what I'm hoping to accomplish (blue are good positions, red is not allowed).
prevent-onunitsphere-overlap.jpg
(98.8 kB)
Comment