Hello, i already made a basic script for that but now i wan’t to control how percent of gameobject will be on center. I don’t now where and how do that. So, can you say me please.
Actually i have that :
public static Vector3 densityInsideUnitSphere
{
get { return Random.insideUnitSphere * Random.Range(0f, 1f); }
}
And that :
for (int i = 0; i < numberOfStars; i++)
{
Vector3 starPos = PixelMath.densityInsideUnitSphere * maxRadiusX;
GameObject star = Instantiate(cube, starPos, Quaternion.identity, this.transform);
}
Use Random.OnUnitSphere with random binominal (Random.value * Random.value) or a random value from 0-1 to some power* as long as they are different values.
*not really a power though… I suppose they are called random tri-nominal quad-nominal and so on?
Another option is to use it with a regular random value that is used to evaluate an animation curve.
Btw Random.value is basically a shortcut to Random.Range(0f, 1f)
Do Random.OnUnitSphere to get a set of directions for each thing. Then multiply each by a random length to get the actual distribution of positions you want.
An even chance to get anything in the range is a uniform random number. The other kind is non-uniform. Searching will give lots of technical stuff at first, but probably also some simpler stuff.
Here’s a hack-tactic but perfectly fine way, which I think SparrowN alluded to: roll and add 4 random 0-5 floats. That gives 0-20, with most results closer to the middle, 10. Easy numbers to think about, and roughly the same idea as 3d6 in dungeons and dragons. To shift results to one end, subtract 10 and take the absolute value. Now you’ve got 0-10, with most near 0. Finally divide by 10 to get 0-1. So: r1=[loop rand(0,5) X4] r=Mathf.Abs(r1-10)/10;.
You can’t get precise odds this way, but more dice == more clumped. You can usually get good results by just tweaking that.