- Home /
Procedural Generation
I am trying to find some guides or information on how to Proceduralay generate stars for my space game.
Need to be more specific, please. By stars, are you wanting to use particles, meshes, GUI, planes with textures? Is it a 2D or 3D game, will the stars be traveled to, or just used for background? Give a bit more detail on what you're going for :)
I am trying to make as real as possible of a 3d space game. I was looking at using particles but did not know if that would take to many to make a good space scene.
If you're using particles, you could attach a particle system to your "ship", and set the particles to "stretched" then give them a velocity scale. This would give a "travel" effect, here's an old space scene I did to show you what I mean.
try using procedural example in unity demos, check out its "Fractal Texture" scene which uses perlin noise based texture, I think you might need to replace its texture with your star sequence sprite, I hope it would be good starting point
Answer by Dave-Carlile · Dec 27, 2012 at 02:43 PM
You don't need anything too sophisticated for this. The key is Random.onUnitSphere, which gives you a random position on the surface of a unit sphere. You can then multiply that by the desired radius to move the point out further. This script gives an example. Create a Sphere game object with a scale of 0.1, assign that to StarObject in the editor. Once you have it working change StarCount to 5000 and you'll have a decent looking set of stars.
Now, using spheres for this is obviously a really bad idea, but I wanted to give a simple example of the procedural part of this. It's just repeatable randomness, and for this particular thing you don't need Perlin.
To make this efficient you could use billboards for the stars rather than the spheres. Better yet, use Pro so you can take advantage of batching - should be able to do the whole thing in a single draw call.
Another option for efficiency (again, requires pro) is to generate the random sky dome using this method, then create skybox textures using render textures, and use those for rendering a sky box. You'd have procedurally generated skyboxes that way - the best of both worlds.
public class StarDome : MonoBehaviour
{
public GameObject StarObject;
public int Seed = 42;
public int StarCount = 500;
public float MinRadius = 100;
public float MaxRadius = 120;
void Awake()
{
// make sure we generate the same positions each time
Random.seed = Seed;
for (int i = 0; i < StarCount; i++)
{
// get random position on unit sphere
Vector3 p = Random.onUnitSphere;
// move it out to the sky sphere distance, with some randomness
p *= Random.Range(MinRadius, MaxRadius);
// instantiate game object
GameObject star = Instantiate(StarObject, p, Quaternion.identity) as GameObject;
star.transform.parent = this.transform;
}
}
}
Is there anyway I can proceduraly generate a ring for my planet I am new to this hole prodedural generation.
Why not? The StarObject could be what you want, f.e. a planet with ring.
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Making a Jetpack 3 Answers
Mouse Look is over riding my controller 1 Answer
Missle Distry after it reaches distance 1 Answer
Distribute terrain in zones 3 Answers