- Home /
Particle emitter detection
Is it possible for a particle emitter to detect when it hits the ground?
I have an empty game object with an ellipsoid particle emitter, particle animator and particle render attached, I have the ellipsoid particle emitter emitting 1 particle that has a velocity of 50 forward, and in the particle render I have the particle stretched so it all looks like a laser bolt being fired, so I was wondering if it's possible for the particle to know when it's collided with anything.
Thanks.
Answer by jmatthews · Mar 26, 2013 at 07:28 PM
Sure, there are quite a few ways to do this. I'll give you the logical instructions and see if you can convert it to working code. If it doesn't work out for you let me know and I'll dig in a little deeper.
Since you are only emitting a single particle, and you know when the particle is emitted you can simply spawn a game object(a collider) with the same position as the emitter and the same movement code. then just respond to the OnTriggerEnter event for the collider.
A more robust, but more difficult solution is to hold a reference to the particle system and use the GetParticles[] array, and use the one given particle to position the collider.
A final approach would be to cast a ray starting at the emitter and going out 50 units per frame until you detect a collision. This one is hackier and could give you false positives if something is moving fast enough to get between the emitter and the target during the time that the raycasts are happening(over several frames)