- Home /
Put out fire with water particleSystem
Hey all- I have a question about using particles to trigger some code much like OnTriggerEnter. Basically I have a particlesystem of water streaming. When a water particle from that system collides with my trigger, I want the fire in my scene to stop. Does anyone know how to achieve this? Seems to be very few or no tutorials on the subject and Unity's documentation for OnParticleTrigger is not really clear to me as a beginner coder
Answer by KittenSnipes · Jan 15, 2018 at 06:13 AM
So this is a script that you would attach to your particle system that streams water:
public ParticleSystem part;
public List<ParticleCollisionEvent> collisionEvents;
void Start()
{
part = GetComponent<ParticleSystem>();
collisionEvents = new List<ParticleCollisionEvent>();
}
void OnParticleCollision(GameObject other)
{
int numCollisionEvents = part.GetCollisionEvents(other, collisionEvents);
int i = 0;
while (i < numCollisionEvents)
{
if (other.tag == "Fire")
{
other.SetActive(false);
}
i++;
}
}
You need to make sure to set the triggers module on the ParticleSystem to on and also turn on the collision module. You need to do that to the water particle system. For the fire particle system you need to turn on the collision module. For each collision module you also need to enable the little checkbox under the collision module which is labeled 'Send Collision Messages'. Also make sure to set the type of the collision module to world. Ill add a video so you can see everything.
Heres that video:
If you have any more questions feel free to comment on my answer :D.
Wow really awesome explanation! Thank you!
I was also wondering- let say my object with the fire is prefab- like a burning crate or tree. I've already set up fire particle systems around the tree to play on certain events. like so:
//This script is on my tree prefab
void OnTriggerStay (Collider other)
{
if (other.tag == "Player" && (PlayerCanlightThingsOnFire)) {
{
fire1.Play ();
fire2.Play ();
smoke.Play ();
TreeOnFire = true;
}
}
I've set the Prefab up to stop the fire when TreeOnFire = false., and to destroy the tree if TreeOnFire == true for 10 seconds.
So I'm wondering if there's a way to set TreeOnFire to false when water particles collide with it (or enter the TriggerBox surrounding the tree). This way the fire will turn off, the TreeOnFireTimer will reset, and all will be well with the world lol
I'm wondering how you would achieve this, and will it work for all prefabs in the scene?
I did exactly the same but it doesn't work. Please can you help me?
Answer by getyour411 · Jan 14, 2018 at 06:21 AM
This looks promising:
https://unity3d.com/learn/tutorials/topics/scripting/particle-collisions