So, I want to create a script that can makes me have random points within a radius. Also, the distance between those objects should have equal distance. Basically, I want to have the points that can create a n side regular polygon that is inscribed in a circle. Anyone have any idea how to do that?
The pseudocode would be something like:
1: find the first random point X 2: pick the number n of points you want 3: create the next (n-1) points by rotating X 360/n degrees around the center.
Finding a random point on the circle is easy - use Random.InsideUnitCircle().normalized, which will give you a point on a circle. Note that this gives you a Vector2, so if you’re working in 3D, and this circle is on the x/z plane, you’ll have to convert the Vector2.
For 3, you can rotate a vector by multiplying it with a Quaternion. Assuming that you want to rotate the vector X 90 degrees, that would be:
Vector3 rotated = Quaternion.Euler(0, 90, 0) * X;
Finally, you want to create the points around the origin (0, 0, 0), and move them to where you want them after you’ve found them, as that’s easier than trying to handle rotating about a point somewhere else.