unity-game-engineparticlesparticle-system

Unity - Particles emitting non-random


I am trying to find a way to emit particles in a non-random direction around and away the object.

Using the Cone shape, with an angle of 90, the particles fly away from the object, which is good. However, the particles are emitted at a random point, as seen here.

I would like the particles to emit at certain angles. One particle north, one particle north-east, one particle east, et cetera.

I created my own octogonal mesh, hoping that it would emit at all the corners, but the emission is still random.

So this is what I would like to do: https://i.sstatic.net/kp0VA.png

Is this possible to do, and if yes, how?


Also, while at it: Is it possible to get the parent from a sub-emitter particle? Every particle emits a small trail, but I can't seem to get a list from the sub-particles, only a list of all sub-emitter particles.

I want to color the sub-particles the same color as the parent. Is this possible?


Solution

  • If you just want to control the direction, using a mesh definitely works. Particles are emitted from the mesh (be it from a vertex, edge or triangle) using the mesh's normal at that point as direction (unless Random Direction is checked), so make sure the mesh's normals are in order. Better still, create the mesh yourself:

        Mesh mesh = new Mesh();
        mesh.vertices = new Vector3[] { Vector3.zero, Vector3.zero, Vector3.zero, Vector3.zero, Vector3.zero, Vector3.zero, Vector3.zero, Vector3.zero };
        mesh.normals  = new Vector3[] { new Vector3( 1f, 0f, 0f), new Vector3( 1f, 0f,  1f), new Vector3( 0f, 0f,  1f), new Vector3(-1f, 0f,  1f), new Vector3(-1f, 0f, 0f), new Vector3(-1f, 0f, -1f), new Vector3( 0f, 0f, -1f), new Vector3( 1f, 0f, -1f)};
        mesh.triangles = new int[] {0, 1, 2}; // Unused triangle that apparently makes the emissor work
        UnityEditor.AssetDatabase.CreateAsset(mesh, "Assets/8DirEmitter.asset");
    

    Pay attention to the Shape settings in the pic. But this way you won't have any control of which one of the 8 directions each new particle takes, so it will look very patchy:

    Eight Directions Particle System, with Shape settings

    If you want decent control of what's going on, hand-code it yourself using ParticleSystem.Emit()

    Edit: The Emit (Particle particle) overload is wrong in the docs. Emit uses UnityEngine.ParticleSystem.Particle, not the legacy UnityEngine.Particle. It's... very confusing. I was just working with particles and this gave me a lot of trouble until I decompiled UnityEngine and saw the input parameters myself.