Place stars (prefabs) in random locations

Hi,

I would like to generate a 3d star field and I was thinking some prefabs of basic small white spheres with a self illuminating shader applied to them would be a good start. Whats a good way of inserting prefabs in random locations or feel free to suggest a better way to go about creating a nice 3d star field.

Thanks

3 Answers

3

How many stars are you wanting to make? I’d use billboarded simple planes (sprites) if it’s a lot

Use a particle system.

Using an ellipsoid particle emitter with a very large ellipse encompassing the entire playable area (generates them everywhere) very large energy (how long each will last) and no forces applied (they wont move) will probably do what you want

–

Rather than a very large number, use "infinity" for the energy, so the particles don't expire.

–

I didn't realize infinity was an option. sweet!

–

What do you think would be less expensive: A 3072x2304 starfield png (seeming random stars) or using a particle system like you say with 3 or 4 like 25x25 star pngs for particles? I currently use the former but am trying to cut all the fat off my system

–

I recommend going the particle system route but if you want to try the prefab way you could use something like this

javascript

var starPrefab : GameObject; // set in the inspector
var starCount : int = 100;
var starFieldSphereSize : float = 1000;

function Start () {
    for (var i=0; i < starCount; ++i) {
        var position = Random.insideUnitSphere * starFieldSphereSize;
        Instantiate(starPrefab, position, Quaternion.identity);
    }
}