Obi Official Forum
Best way to remove particles at runtime - 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: Best way to remove particles at runtime (/thread-2637.html)



Best way to remove particles at runtime - ary1111 - 16-12-2020

So I'm trying to have particles disappear when they collide with an object. I have tried three methods but all seem to cause the emitter to behave weird. When the particles collide with the object they do disappear but it seems like at a certain point (30 seconds in), particles just disappear as soon they emitted when I use either one of these methods.

Code:
    private void Solver_OnCollision(ObiSolver s, ObiSolver.ObiCollisionEventArgs e)
    {
        var world = ObiColliderWorld.GetInstance();
        foreach (Oni.Contact contact in e.contacts)
        {
            // look for actual contacts only:
            if (contact.distance < 0.01f)
            {
                var col = world.colliderHandles[contact.other].owner;
                if (col.tag == "Outlet")
                {
                    Debug.Log("Remove Particle");
                    if(method1)
                        emitter.solver.actors[0].DeactivateParticle(contact.particle);
                    else if(method2)
                        emitter.life[contact.particle] = 0;
                    else if(method3)
                        emitter.KillParticle(contact.particle);
                }
            }
        }
    }

Is there a standard way for removing specific particles when a collision takes place?


RE: Best way to remove particles at runtime - josemendez - 16-12-2020

The indices provided by contacts are solver indices. You need to convert them to actor indices first, as per the docs:
http://obi.virtualmethodstudio.com/tutorials/scriptingcollisions.html

Quote:IndexInActor

The index of this particle in the actor's arrays. For instance, you can kill a ObiEmitter particle upon collision by doing this:

Quote:ObiSolver.ParticleInActor pa = solver.particleToActor[contact.particle];
ObiEmitter emitter = pa.actor as ObiEmitter;

if (emitter != null)
    emitter.life[pa.indexInActor] = 0;



RE: Best way to remove particles at runtime - ary1111 - 16-12-2020

I see, thanks for the quick response and explanation! I am able to properly kill the particles now.