Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Help  KillParticle after collision and shouldn't return
#1
Good Morning,

I am having an issue that I am hoping to get some help on.

- I have a collider that will destroy individual particles when collision takes place. I need to Disable, Kill, change Life of the singular particle so that it doesn't go back into the pool and get re-emitted.


Scenario: Barrel tips over, at certain angle emitter speed goes up, emission begins. The particles that have been emitted and then collided with get "cleaned" up and in this process, destroyed and prevented from going back into the emitter pool.

Just having trouble with the code line for disabling the particles from the pool that have been collided with. 

Thanks!

What i have thus far:

if(collider.tag == "ParticleKiller")
                    {
                        
                        
                        // do something with the collider.
                        int killThisParticle = solver.particleToActor[contact.particle].indexInActor;
                        emitter.KillParticle(killThisParticle);
                       
                        // get particle indices and 
                        
                            //disable from active emitter


                    }
Reply
#2
I have created a work around for now.

public class StopEmitterMaxParticleCount : MonoBehaviour
{
    public Obi.ObiActor actor;
    public Obi.ObiEmitter emitter;
    public float maxParticleCount;
    public float particleCounter;
   
    public float emissionSpeed = 1;
    
    // Start is called before the first frame update
    void Start()
    {
        actor = GetComponent<ObiActor>();
        emitter = GetComponent<ObiEmitter>();
        emitter.speed = emissionSpeed;
    }

    // Update is called once per frame
    void Update()
    {
        
        print("actor.activeParticleCount = " + actor.activeParticleCount);
        //print("actor.particleCount = " + actor.particleCount);
        
        if(actor.activeParticleCount == actor.particleCount)
        {
            emissionSpeed = 0f;
            emitter.speed = emissionSpeed;
        }
    }
}


this in conjunction with my other script that kills the particle works for my purposes for now. Although I would like the ability of not needing to stop the emitter, rather just deactivating the killed particle at it's indices. This way if a barrel only spills some of its contents, it will still retain the ability of spilling the rest, however still allowing me to cleanup was has already been emitted and those particles not going back into the pool.

Once I have that setup I will post again. For now my prototype can move forward.
Reply
#3
Code:
if (emitter.isEmitting) // or when you emit your first particle
emitter.minPoolSize = 1;

This would work in your case, I think. minPoolSize prevents emission from starting until the percentage of pooled particles is above its value. So by setting it to 1 (100%) while emitting will prevent emission from restarting until there's more pooled particles than the blueprint's capacity, which will never happen. So once the barrel is empty, emission won't restart.
Reply