- Home /
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 [i] = 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<ParticleSystem> ();
gManager = GetComponent<scriptGalaxyManager> ();
sParticles = new ParticleSystem.Particle[gManager.systemPositions.Length];
int s = pSystem.GetParticles (sParticles);
for (int i = 0; i < s; i++)
sParticles [i].position = gManager.systemPositions [i];
pSystem.SetParticles (sParticles, s);
pSystem.Emit (sParticles.Length);
pSystem.Pause ();
}
However I am having issues with things lining up.
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.
'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
Anyone else have any ideas, by doing some more searching I guess what I am creating is a Point Cloud. By looking at other posts ..GetParticles(...) and ..SetParticles(...) does seem to be the way to do it so I must just be getting something wrong. Are particle positions still regular (x, y, z) coordinates?
Answer by TobyKaos · Sep 12, 2016 at 12:19 PM
Are the same origin for both?
Yea, both are at at 0, 0, 0. I've tried different rotations of each to try find alignment and also parenting. Nothing seems to come close.