Obi Official Forum
How to destroy particle from it's position - Printable Version

+- Obi Official Forum (https://obi.virtualmethodstudio.com/forum)
+-- Forum: Obi Users Category (https://obi.virtualmethodstudio.com/forum/forum-1.html)
+--- Forum: Obi Fluid (https://obi.virtualmethodstudio.com/forum/forum-3.html)
+--- Thread: How to destroy particle from it's position (/thread-967.html)



How to destroy particle from it's position - anonymous - 09-03-2019

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);
               }
           }

       }
   }



RE: How to destroy particle from it's position - anonymous - 13-03-2019

(09-03-2019, 03:48 PM)anonymous Wrote: Hi.

So is it possible to do this efficiently? Any help



RE: How to destroy particle from it's position - josemendez - 13-03-2019

Hi,

Use contact callbacks to determine what particles are inside a given trigger collider, instead of looping trough them all:
http://obi.virtualmethodstudio.com/tutorials/scriptingcollisions.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.


RE: How to destroy particle from it's position - anonymous - 15-03-2019

(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!