- Home /
2D Game - How to Create an starfield with particle systems
Hi,
I'm trying to create a starry sky for a 2D game using Unity's particle system. Is it possible to create particle emission only once? And after that only work with the alpha of emitted particles? (Blink effect)
I have something like this:
But it gets emitted all the time, is it possible to do what I'm thinking?
I would like something like this:
I appreciate any tips, even if that is not the best way to do it.
Thank you!
Answer by ifurkend · Jan 22, 2017 at 05:36 AM
You set random between 2 very high constants of start lifetime about the expected duration of your scene. For the blinking effect, if you are using Unity 5.5, the looping function for curve graph is really helpful to repeat the curve. Refer to my attached image, in the Size over Lifetime curve graph, I set 5 linear points with the middle one dipped to zero. Then at the right end of the curve there is a cog and you can click it to set "loop". Finally press "Ctrl+A" in the graph to select all visible points, there is 4 "scaling" blue lines, drag the right vertical blue line leftward and you can see the pattern of the curve is repeated. Because you have already set "random between 2 lifetime constants", you don't need to worry about the particles blinking in the same moment. If you are using older Unity, then you will need to repeat those points in the curve graph manually.
Lastly about performance with texture/material: Normally you would use a star/flare texture for better result, but if you are concerned with performance, you may downgrade the material to just unlit-color shader which is opaque instead of alpha. Alpha overdraw is something you want to reduce as much as possible especially for mobile game.
@ifurkend Thanks for response!
I got something like this before your answer. I'll do as you said to see the result. One doubt ... is it possible to generate the "stars" only once? Rather than being generated at random points? I need them to just blink
That depends on how much randomness you want to avoid. If you want the stars to appear on fixed positions, you create a mesh where vertices are the point of spawn and import it to Unity. In Unity, position your imported mesh, attach your star particle object under it and change emitter "shape" to "mesh renderer", load that mesh object. However, because the default particle UI does not provide a way to avoid overlapping even if the max particles count equals the vertices of your mesh, you will need to loop through the ParticleSystem.GetParticles via script to assign each particle to $$anonymous$$esh.vertices which I haven't done before.
I wish the stars were fixed in one place, just by varying their light (blinking). How would it be: "create a mesh where vertices are the point of spawn and import it to Unity"? Was it an image with the stars?
Thanks
Your answer
Follow this Question
Related Questions
Did the behavior of gravity of particleSystem ever changed? 0 Answers
[Tank Game Tutorial] Particles Only Appear While Turning 2 Answers
Teleporting old particle system 0 Answers
Start/Stop a Particle System 2 Answers
ParticleSystem at Photon Not working! 2 Answers