Extinguish fire

Hi,

I have been try to extinguish some fire particles after they come in contact with the fire extinguishers particle system. I am a bit confused on what to write in my script. Any help would be appreciated.

I did a quick search for this… I know something like this is probably possible, but I don’t know how to write it off hand.
How much accuracy do you require?
I ask because I play a game where you can very occasionally put out fires, but the extinguisher you use and the fire you see, though they have particles, I don’t think they are actually responsible for the event, if that makes sense.
A Player simply has to be aiming at any part of the fire and after 2-3 seconds, it’s considered extinguished, so long as each “tick” counts up to the # required to put it out … that’s how I imagine it works, in my head/from observation.
Would something like that be suitable in your situation?

If not, you can google particle collisions and stuff… I Saw some answers online & even a tutorial from Unity, etc… :slight_smile:

So something like this I imagine. Well I was hoping that after a certain while of aiming at the fire with the extinguisher the fires health decrements and if its 0 you destroy the fire system. Do you rely on like a time out or something to close the fire after 2-3 seconds after its instantiated? For example, if there was fire already and i did not use the fire extinguisher will the fire automatically close after 2-3 sec? Also, when you say very occasionally do you mean 9/10 you put out a fire? Regardless, I would like to see a sample code :slight_smile: They said online that shuriken particle collisions cannot recognize other particle collisions.

No, no, when I said occasionally I meant that that is a small feature/occurence in the game - putting out fires. It just doesn’t happen often in the game that there is a fire/extinguisher to use :wink:

Ah okay, I didn’t read too in-depthly on the subject. They can do collisions, but I guess with non-particles.

In my thread response before, I was asking if it was enough to simulate putting out the fire without direct particle - to - particle interaction. You could, say have a box or sphere collider that is somewhat close to the size of your extinguisher’s particles… Your extinguisher has a timer (or can go indefinitely - doesn’t matter), but so long as it is touching every 1/2 second or second on the fire, then the fire’s health goes down… when it’s <= 0, it’s out. That’s what I was thinking.

The link you posted is a very similar idea, but using particle collision (against I think the gameObject colliders of the fire?)… and using the old particle system**.

Really up to you how you go :slight_smile: But at least you have some options.

Unfortunately I am stuck using the shuriken particle system so I guess ill have to use box colliders or any other collider. But I am a bit confused on how to actually implement a code like you described :frowning: When you say without direct particle to particle interaction like will it be blatantly obvious to someone if they saw it? So what i understood is that the fire extinguisher particle system needs a collider along with the flame particle system (I think? ) and when a collison occurs it will decrement until it reaches <=0.

Ya, maybe you decrement the health during OnCollisionStay or OnTriggerStay … this is just an example I thought of.

And with regard to Shuriken, I was suggesting that you switch… I’m 99.99999% positive the methods in the link you posted are doable in the new system, also (it’s just maybe different code, I don’t know exactly).

But by not particle to particle yes I meant that you would approximate it. Even with the particle collision you’re approximating, I’m pretty sure. If particles don’t collide directly, you could only ever hit a collider on the main object anyways. To be honest, I don’t see how that’s much different - not in your case where the extinguisher’s output is pretty deterministic (in terms of radius/range)… I mean if you had particles floating all over the scene, sure, maybe the other approach would work… I’m babbling.

Yep, 2 colliders… and just try it out :wink: See what happens. lol
Will it be obvious? I don’t think so… games are much about imagination and if your collider is approx the same size, it’s all good, but you won’t know until you try :slight_smile:

Thing is I bought an fire extinguisher asset and it is already using the shuriken particle system by default and im too lazy to change it :slight_smile: Regarding the code in the link now the person closes the fire using this function:

  • void OnParticleCollision(GameObject other) {
  • if(IsOnFire) {
  • FireHealth -= 1.0f;
  • if (FireHealth <= 0) {
  • IsOnFire = false;
  • transform.GetComponent().emit = false; // more specifically this command
  • // other things to do when fire goes out
  • }
  • }
  • }

So if i were to close a shuriken particle system how would i write that? particleEmission? there is another value where you can completely switch off the particle system but its a bool value and it wont let me write to it. Moreover, the function that I am thinking to use for the 2 colliders is (void OnCollisionEnter). The only reason I was asking about the obvious part is because I plan to use this in VR and if the user can differentiate that the particles arent actually hitting the fire sooo :hushed:

Sorry, too late in the day to look up how to disable the particles… can’t be that hard.
I see what you mean about the VR… I mean if you come up with another solution that’s cool…
If you have VR, test it and see how it looks :slight_smile:

Ah kk do you happen to have/know any sample script for the collision part I feel like I am doing something wrong and I cant exactly figure it out.

I actually worked on a Fire System in a recent game. The way I did it was that while “shooting” the extinguisher it would raycast in ticks to where ever its was pointing. Then each fire asset would have a root transform with a simple Box/Sphere collider, a model on a child transform and several particle systems under another child transform. when the raycast hit the fire’s collider it would send a call to the fire with reactant data from the extinguisher (the game had different types of extinguishers for different kinds of fires, just like in real life). so depending on the type of reactant it would affect one of the properties of the fire, strengthening or weakening it. for example water extinguishers can make chemical fires worse.

The Extinguisher’s Particles and the Fire’s particles don’t directly affect each other they are simply visuals. its the raycast against the collider… which calls code on the fire script… which changes the state of the fire… and thus changes the strength of the particles. Particle Collision can just be far too expensive if not done correctly, and I can’t assume they always will be when someone else sets up the particle systems. Raycast is a lot faster not tightly coupled to what ever particle system you decide to whip up, and much, much more consistent.

If between Joshua’s and my posts/suggestions, you aren’t quite finished, you could post your code and maybe me/someone can help you out?

Still not finished sadly :frowning: This is wat I have done so far:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class fire : MonoBehaviour {
    public float FireHealth = 10;
    public float MaxFireHealth = 50;
    public float HealthRegen = 0;
    public bool IsOnFire = true;
    //public ParticleSystem Fireparticle;
  
    // Use this for initialization
    void Start() { }
   

    public GameObject explosion;
    public GameObject fireyy;
 
    void OnCollisionEnter(Collision col)
    {   if (col.gameObject.name == "Cube")
        {
            GameObject expl = Instantiate(explosion, transform.position, Quaternion.identity) as GameObject;
            Destroy(gameObject); // destroy the grenade
            GameObject firedup = Instantiate(fireyy, transform.position, Quaternion.identity) as GameObject;
            Destroy(expl, 2);  // delete the explosion after 2 seconds
           
          
          
           if (col.gameObject.tag == "flamed")
            {
               Destroy(firedup, 3);
            }
        }
       
      // if (col.gameObject.tag == "flamed")
        //{
          //  fireyy.GetComponent<ParticleSystem>().isPlaying)
            //Destroy(fireyy, 3);
            //transform.GetComponent<ParticleSystem>().enableEmission= false;
      //      flameparticles.enabled = false;


        //}


    }


 

    // Update is called once per frame
    void Update () {

      
        if (IsOnFire)
        {
            FireHealth += Time.deltaTime * HealthRegen;
            if (FireHealth > MaxFireHealth)
            {
                FireHealth = MaxFireHealth;
            }
        }


    }
}

Idk if i am doing the call rite so after my object hits the cube an explosion takes place (which gets destroyed after 2 seconds) and another fire object is instantiated. I added another if statement in the if statement that would detect if it collides with the fire ext tag then it will destroy the fire. But when I run this code it doesnt work. I made sure that the box collider of the fire extinguisher is colliding with the fire and the fire has a mesh collider attached to it. I think I am doing something wrong in the if statement. I tried closing the particle system in other ways besides destroy by emissionrate or enableemission but no luck. :confused:

Hmm… What if you just make the fire part and try to get the extinguisher to put it out (First) , then add the grenade after and such? :slight_smile:
Let’s go back a bit, if this isn’t working. How long does a player have to keep the extinguisher on the fire to put it out?

Really depends on the counter till it decrements goes to 0. Its either that or i call the enableemission component or emission rate and turn it off after a few secs if its in contact with the fire ext. I cant seem to figure out the proper way to destroy the fire after its instantiated. If i try to destroy the prefab itself Unity wont let me and the only other way to destroy the fire is playing around with the emission which I have no idea why it wont let me close it :confused:

Um, I did a quick search around for disabling the emission directly; I’m curious, though, is the fire ever returning or if it’s just okay to destroy the object (maybe some gameobject that contains the fire)… would be easier?
Fire starts (grenade, whatever) → creates object which has emitter for fire + a collider…
You’re on your way to put out the fire, and your extinguisher aims and fires at this collider… duration over the collider is putting out the fire… when it’s out, destroy this “holder” object?

The fire doesnt return it should just go away. Until instantiated again. When you say creates object which has emitter for fire + a collider are you planning to call the emitter function? If by holder object you mean the variable where the fire got instantiated from aka (GameObject firedup = Instantiate(fireyy, transform.position, Quaternion.identity) as GameObject; ) fired up then yes you need to destroy firedup.

Sure, I use vague names/terms because I am not 100% certain what you have in your mind. So I don’t want to say the wrong name :slight_smile:
I was a little unclear on your first question, but whatever gameobject you instantiate that has an emitter on it… if you put a collider on that and on that object, you have “OnCollisionStay” or “OnTriggerStay” if it’s hitting your extinguisher, decrease its health and put it out (destroy it)?

nah its fine sorry if i am being a bit unclear. Yea either that or i was thinking to use destroy with a timer but thats not possible.

Destroy with a timer is possible, for sure… I just think either decreasing over time is a little better…
but what would be probably a bit more efficient is like “pulse” decrease. lol depends… probably no one right answer.

Timer would just have to keep track of how long you’re on it, because you can’t really set just 1 time and forget it, because what if you move away from the fire … then obviously that shouldn’t be counting.

I think you should try something really simple like: just start a scene with a fire… gameobject + fire + collider
then put yourself right there in the scene. with extinguiser (that has a gameobject with particles that appears when you turn the device on + collider)
write a small script to put out the fire…
Then when you see that working make it bigger with your grenade and whatever else you want to do later :slight_smile:

Hmm will look into it. currently I am facing two problems i feel like I am calling the wrong tag or collision component. Or if thats not the case then its either on how should I destroy the particle component and I cant seem to wrap my head around how to turn off the emission or cause the particlesystem to just stop or how to use the destroy function in Void OnCollisionEnter :frowning: