Spawning individual particles at scene coordinates.

So i’m messing around with creating a ‘galaxy’ type star field. I have one gameobject that creates a Vector3 array of star positions using a for loop and Random.insideUnitSphere then it creates gameobjects at those positions.

// Spawn Systems.
for (int i = 0; i < systemCount; i++) {
      Vector3 pos = Random.insideUnitSphere * galaxySize;
      systemPositions  *= pos;*

GameObject s = Instantiate (prefabSystem, pos, new Quaternion (0, 0, 0, 0)) as GameObject;

  •     s.transform.SetParent (transform);*
    

}
After that I have a ParticleSystem gameobject that accesses that Vector3[] and tries to create particles at those positions.
public void PopulateParticleSystem() {
pSystem = GetComponentInChildren ();
gManager = GetComponent ();

sParticles = new ParticleSystem.Particle[gManager.systemPositions.Length];

  • int s = pSystem.GetParticles (sParticles);*

  • for (int i = 0; i < s; i++)*
    sParticles .position = gManager.systemPositions ;

pSystem.SetParticles (sParticles, s);
* pSystem.Emit (sParticles.Length);*
* pSystem.Pause ();*
}
However I am having issues with things lining up.
[78082-galaxy.jpg|78082]
The sphere colliders are gameobjects that have been Instantiated at the systemsPosition vectors and the white dots are the particles.
Both the galaxy size and particle sphere radius are set to 10,000.
The parenting hierarchy.
[78084-parenting.jpg*|78084]*
‘galaxyManager’ is what the above script is running on and ‘particleSystem’ is the particle system it is accessing. Both are at position (0, 0, 0).
Does anyone have any experience with this type of thing and can lend a hand, Let me know if you need any more details.
Thanks
- Matt
*
*

Are the same origin for both?