Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to destroy particle from it's position
#1
Hi.

I need particles to be killed once they are below a given position.y
In my situation, the particles should live as long as they don't fall below some position. Once enough are killed, new ones would be emitted.

Here's my code for now but something is not right. It finds the particle pos but the kill part does not seem to work because my active particle number (in the emitter inspector)  stays the same when running. If possible, I would like also something less demanding than having to regularly loop through the array to do the pos check. 
Code:
  IEnumerator PurgeParticlesTooLow()
   {
       while(true)
       {
           yield return new WaitForSeconds(5);

           Vector4 v4;
           for (int i = 0; i < obiSolver.positions.Length; ++i)
           {
               v4 = obiSolver.positions[i];
               print("pos particle: " + v4);
               if (v4.y <= GlobalVars.cstBallBreakPointY)
               {
                   obiEmitter.life[obiSolver.particleToActor[i].indexInActor] = 0;
                   print("killed particle at pos: " + v4);
               }
           }

       }
   }
Reply
#2
(09-03-2019, 03:48 PM)anonymous Wrote: Hi.

So is it possible to do this efficiently? Any help
Reply
#3
Hi,

Use contact callbacks to determine what particles are inside a given trigger collider, instead of looping trough them all:
http://obi.virtualmethodstudio.com/tutor...sions.html

Note that the amount of used particles in the solver stays the same regardless of how many active particles there are in the emitter. This is because the emitter pool is allocated all at once.
Reply
#4
(13-03-2019, 11:15 PM)josemendez Wrote: Hi,

Works like a charm. And this way I also get a nice continuous flowing effect like a waterfall instead of bursts.

Thanks!
Reply