- Home /
Get all particles within trigger collider?
I have a trigger collider on an object. I also have multiple Particle Systems nearby. Some particles will end up inside of the trigger collider, at times. I would like to know when each particle is inside the bounds of the trigger collider. This is to be done from the perspective of the trigger collider object, not the particle systems, because it should work for any arbitrary particle system without having to apply a component to each one of them; I only want to apply a component to the trigger collider to track these particles, ideally.
If you're wondering why I want to get all particles within the trigger collider, it's because I'd like to apply a force to all particles within the trigger collider, for each frame that one is in there.
Thanks for any suggestions. I'm hoping to figure out the most efficient way of doing this.
Answer by richardkettlewell · Jul 04, 2018 at 09:04 PM
You gotta do it from the particle API: https://docs.unity3d.com/ScriptReference/ParticleSystem.TriggerModule.html
That requires modifying the Particle System. $$anonymous$$y goal is to have the trigger collider object itself apply effects to triggering particles, regardless of which Particle System each triggering particle is from. The way I've approached it thus far is by finding all Particle Systems in the scene and doing x,y,z position checking on each particle to check whether it is within the cube region defined by the trigger collider. However, I think this could be done more efficiently.