Search Unity

Is it possible to randomly emit particles but choosing their positions in a 2D grid?

Discussion in 'General Graphics' started by MayIAsk, Dec 6, 2021.

  1. MayIAsk

    MayIAsk

    Joined:
    Apr 11, 2016
    Posts:
    9
    Hello,

    Is it possible to randomly emit particles but choosing their positions in a 2D grid?

    For example:



    The blue points are spawning possibilities and the red points are the particles currently emitted.
    I didn't find the right way to do it when using the Particle System component.
    Can someone give me an hint on how I could achieve it please ?

    Thanks!
     
  2. Lo-renzo

    Lo-renzo

    Joined:
    Apr 8, 2018
    Posts:
    1,511
    Code (CSharp):
    1. public class Emitter : MonoBehaviour
    2. {
    3.     public ParticleSystem ps; // plug in via the Inspector
    4.  
    5.     public void Emit(Vector3 pos)
    6.     {
    7.          ParticleSystem.EmitParams ep = new ParticleSystem.EmitParams
    8.          {
    9.               position = pos,
    10.               // LOTS of other parameters if you want to specify color, velocity, etc
    11.          };
    12.  
    13.          ps.Emit(ep, 1);
    14.     }
    15. }
    You set up the particle system to have the material / texture you want and some initial parameters. Then you can manually emit at particular positions on your grid, selecting from the possible emit spots.
     
    richardkettlewell likes this.
  3. MayIAsk

    MayIAsk

    Joined:
    Apr 11, 2016
    Posts:
    9
    Thank you for answering!
    I think I got it, I have to define the positions myself and my particle system should emit the point texture where I want.
     
    Last edited: Dec 6, 2021