- Home /
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
Answer by Eric5h5 · Aug 26, 2011 at 06:00 AM
Use a particle system.
Are you suggesting that I generate them then freeze them in place? Not sure I would want them moving otherwise.
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.
What do you think would be less expensive: A 3072x2304 starfield png (see$$anonymous$$g 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
Answer by DaveA · Aug 26, 2011 at 05:56 AM
How many stars are you wanting to make? I'd use billboarded simple planes (sprites) if it's a lot
Answer by Rennat · Aug 26, 2011 at 04:09 PM
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);
}
}
Your answer
Follow this Question
Related Questions
Spherical Light for Solar System Illumination 0 Answers
How to make a universe scenery 2 Answers
Render 3D object to a 2D texture at runtime 1 Answer
Weapons Range Projectile script 1 Answer