Best practice to detect intersection with particles

Hello everyone :smiley:

So during my free time Im creating a browser bomberman game and currently I am trying to implement explosion logic and looks. This is how it looks in the game:

I am using a particle system with custom sprites to create a fire effect. [fire playground example]: https://www.babylonjs-playground.com/#1WUQ1S#72

I am also simultaniously using planes (red stripes amid fire in the vid), which I use to detect intersections with players, walls, blocks. [planes playground example]: https://playground.babylonjs.com/#Q9VZS9#277

But this implementation seems so clumsy, so I am wondering if there is an efficient and optimised way to detect intersetions with particles of the Particle System in Babylon? As far as I am awared if I want to detect intersections with particles I should use SPS, but wouldn’t it be an overkill? And wouldn’t it be inefficient in gentral to try and detect particles for intersections, cuz you know, there are so many of them :upside_down_face:

Or maybe there is a better approach in general, that I am not awared of? May be it would be better to use vertex shaders on the mesh for explosion expansion and fragment shaders for the looks?

Sorry for such a long question, I would appreciate any thoughts and ideas on this topic :wink:

P.s. in the fire playground example I also decrease the lifetime of PS and particles to simulate the situation where the fire hits the wall for example and cannot travel further. But this kind of approach seems clumsy as well. Is there a better way to do such a trick?

2 Likes

Hello there! First of all, your game is looking super cool :smiley:

I don’t think there is a better way of doing what you are doing already, as checking intersection against 1 plane in each direction will always be much better than checking intersection with hundreds or even thousands of particles :thinking:

2 Likes

Thank you, I am so happy to hear that you think it looks cool :smiley:

Yeah, when I started to implement explosions in the game my initial thought was that checking for intersections with single plane would be better than with PS. But I wasn’t sure if it was a good practice, cuz it feels a bit clumsy for me to implement the movement logic for planes through scaling and positioning and then implement the same movement logic for PS through lifetime, emitRate and emitPower.