Hey!
I’m looking for a way to instantiate an object and position each one around the orbit of another object.
My brain is having a hard time figuring out how I would randomly plot points around the orbit path to instantiate an object to.
This is my instantiate code so far.
var ball : Transform;
function Start () {
for (i=0; i<10; i++){
Instantiate (ball, Vector3(i * -2.0, 0, 0), Quaternion.identity);
}
}
If someone could point me in the right direction I would really appreciate it.
Figured out how to do it, but the objects are distributed/spaced evenly depending on how many I instantiate. I would like to get a bit of randomization into it. Some objects are slightly up or down in the Y axis, some objects are closer together than others, etc.
Here is my new code :
var asteroid : Transform;
var asteroidCount = 100;
var radius = 50.0;
function Start () {
for (i = 0; i < asteroidCount; i++){
var angle = i * Mathf.PI * 2 / asteroidCount;
var pos = Vector3 (Mathf.Cos(angle), 0, Mathf.Sin(angle)) * radius;
Instantiate(asteroid, pos, Quaternion.identity);
}
}
Found Random.Range and used it for the Y property of the position. Works great. Now am working on getting random rotation for each instantiated object using Random.rotation.
//Set a random position.
var randomYPosition = Random.Range(-0.2, 0.2);
//Set position of each ball.
var pos = Vector3 (Mathf.Cos(angle), randomYPosition, Mathf.Sin(angle)) * radius;
Although you’ve got it working, if you wanted, you could simplify that by using Random.insideUnitSphere.
–Eric