- Home /
Unity 3D Starfield Particle System Help
I'm stuck on how to make a 3D Starfield that I can fly through to give a sense of motion. I've got so far a working skybox, but the particle systems that aren't doing what I want.
In a 2D top down space game, one could easily make 2 layers of stars moving at different speeds to create a parallax effect. I was trying to do something similar, but after a certain distance the particles wouldn't draw anymore.
What I've tried:
sphere emit around the player, emit source moves, but everything is world simulated; this emitted too much when I'm not moving fast, and too little when I am.
3 planes (well, short but wide boxes) of different distances, but the furthest one gets clipped from draw distance. And it isn't far enough to give that sense of parallax.
I'm new to Unity and I'm trying to make a simple 3D (2.5D) Spaceship Game as a way to learn Unity and its components. Please help :)
Here's an example of the scene (don't mind the coloured stars... just checking which systems I can see):
why not use a combination of planes and skyboxes... btw you can change the draw distance
Yes, exactly. I tried to use a combination of planes and skyboxes, but draw distance didn't allow this.
How do I change draw distance?
Found the draw distance. Got things to look "ok", but I guess because the camera is kind of 3D it's not working out so well and doesn't look realistic...
Any ideas on how to implement a 3D starfield for a game like Wing Commander?
Answer by Loius · Apr 12, 2013 at 05:57 AM
Well, stars really aren't close enough together for you to see them move very much as your ship moves, so realism is already out the window. :)
Keeping star density in 3D as you move is a daunting undertaking. I honestly don't know of a solution other than maintaining them yourself - on startup, generate stars within a sphere around player. When a star leaves the sphere, fade it out and fade another in on the opposite side.
Something like this untested mess:
var starsMax : int = 200;
var starDistance : float = 100;
private var stars : List.< Vector3 >();
private var tx : Transform;
private var starDistSqr : float;
function Start() {
for ( var i : int = 0; i < starsMax; i++ ) {
stars.Add(Random.insideUnitSphere * starDistance);
}
starDistSqr = starDistance*starDistance; // to allow use of the faster sqrMagnitude property
tx = transform;
}
function Update() {
for ( var i : int = 0; i < starsMax; i++ ) {
if ( (stars[i] - tx.position).sqrMagnitude > starDistSqr ) {
stars[i] = (tx.position-stars[i]).normalized * starDistance;
}
// display star somehow - SpriteManager can make this a reasonably painless operation
Debug.DrawLine(stars[i]+Vector3.up,stars[i]-Vector3.up,Color.white);
Debug.DrawLine(stars[i]+Vector3.right,stars[i]-Vector3.right,Color.white);
Debug.DrawLine(stars[i]+Vector3.forward,stars[i]-Vector3.forward,Color.white);
}
}
Your answer
Follow this Question
Related Questions
Tips for particles on IOS 2 Answers
How to create a distant asteroid field? 2 Answers
3D starfield with shuriken 3 Answers
How to Create Shields 2 Answers
Atmospheric re-entry effect 0 Answers