Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Best way to remove particles at runtime
#1
Pregunta 
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?
Reply
#2
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/tutor...sions.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;
Reply
#3
I see, thanks for the quick response and explanation! I am able to properly kill the particles now.
Reply