How do I Recognise All Objects That Can "Catch Fire"

Get help using Construct 2

Post » Mon May 01, 2017 1:03 am

Hey there,

I'm going to be a bit detailed and specific with my request, so I can easily relate to everyone and my request for help.

My goal:
Allow any objects in my game to "Burn", "Catch fire" and "get destroyed from the fire", not just one object.

What I have done:
I have sucessfully programmed one object to be able to catch Fire, namely an "AppleTree", and it works great! It burns, and after a while, it will change it's animation to show that it is burnt after it's "Health" value reaches 0. I have also successfully created the concept of spreading fires to other AppleTree objects if the burning fire in question is touching another AppleTree.

What I was working on before I got lost:
Since the AppleTree object is the only thing that can burn in my game at the moment, I wanted to expand the possibilities here, so anything can catch on fire. The trouble is; every object has different variables and the event system recognises each object differently for different things. For example, I have not given the object "Shop" the same variables or events as the AppleTree to catch on fire, etc. So I thought what if I changed the AppleTree into "FireCloak". So it would be an invisible object, and the idea of this would be to use the FireCloak object to cover all objects that can catch fire in the game, so then, using the existing events, it can spread or catch Fire to any object. The reason why I changed AppleTree into FireCloak is because the object for AppleTree has all the programming I need for it to catch on fire (of course).

What I am stuck with:
The only thing I need to make sure of here (and correct me here if I'm wrong) is to recognise the visible object that is burning to change it's animation to the appropriate "burnt" animation. Now, I could do something like this, which, apart from the sub-event, I had, except I created the sub-event to consider different types of objects.

Event Conditions:
Is FireCloak overlapping Fire
Is Burning
Is Health = 0

Sub Event:
Is FireCloak overlapping AppleTree

Event Actions (for sub event):
AppleTree Set Animation to "Burnt"

However, in my game, objects, and particularly objects like Trees can overlap each other for a graphical effect. If I used the same code here to change the animation of an AppleTree to burnt when it is overlapping another AppleTree that is not ready to change it's animation, it will pre-maturely happen, and it will likely cause other bugs I do not want. So, I am trying to figure out a way I can match each FireCloak with their respective objects.

Possible solutions I am looking at:
1) I thought about Containers, but this only works effectively if you're talking about the same object and it's instances, I have multiple objects with different variables, I would have to spend a lot of energy and time in changing a lot and this could also cause bugs with other objects, so I am not keen on this.
2) I was seriously thinking I could create a variable under the FireCloak object which will be "Object_UID" and I would then somehow assign the UID of the appropriate object to the FireCloak, then when it comes to changing animations to Burnt, I can just compare the object's UID with the FireCloak's Object_UID variable, and if it matches to change the animation. The only thing I am stuck with here is how do I do this without having to copy FireCloak and then specifically change the object_UID variable to each appropriate object. I suppose this does not matter so much, Flammable objects on a level will not be changing shape, size, or position.

Please tell me what you think, is my solution 2 the best and most effective solution?

Thanks so much in advance!
B
11
S
3
G
2
Posts: 36
Reputation: 1,811

Post » Mon May 01, 2017 1:11 am

I have made similar systems in the past.

The way I did it, was anything that I wanted to be able to burn had it's own set of instance variables, basically to control things like "IsOnFire:0/1" or "BurnRate:X" etc.

I then had a single event for each burnable item that checked if fire existed, and if it did to check what it's overlapping, and if it's overlapping anything that has the variable "IsOnFire" and that value was "0" then it would change to 1.

Once this variable was set to 1 (or whatever you want to make it be) then I had one more event that would create fire sprites, etc.

I used "Fade" behaviour on the fire to give it an automatic lifespan (if it was overlapping nothing burnable, or something that had already burnt). Essentially what you want to try and create is a blanket system that works on anything by building a "fire system" that you can add objects to by either including them in a family (called BURNABLES or something) or by creating one event per burnable item. I went with using separate events myself because my burnables had very different effects on them depedning on the thing that was burning... but if you want a nice generic burn effect that looks pretty much the same on all or most items, using a family would be a good way to do it.

Remember that you can easily add all objects to multiple families... so you can make a BURNABLE family, and add objects to it that might be part of some other family already, and that should work just fine.

Hope this helps a bit!

*EDIT*
I forgot to mention, what I created to solve my issue was basically what's referred to commonly as a "state machine" - wherein you have a sequence of steps that will happen when fire is encountered. IE: Step 1 check for fire, Step 2 initiate burn if applicable, Step 3 generate fire effects and particles/etc, Step 4 change to "Burnt" state and set animations, Step 5 destroy or invalidate. I actually use a string based instance variable that I call "STATE" and set it to whatever text word I feel is appropriate - like "fresh" and "burning" and "burnt" - then use these "state words" to jump from the initial state to the next and next, and so on.

~Sol
Tired of crappy file hosts that are crappy? Get DROPBOX - https://db.tt/uwjysXJF
Moderator
B
81
S
34
G
40
Posts: 3,031
Reputation: 30,422

Post » Mon May 01, 2017 2:13 am

Hey SoldjahBoy,

Thanks for the prompt response. It was very quick.

I have not done much family stuff in my project. I have studied families, and perhaps in some cases I should use them, and I might, but in this case, I think the best thing for me to do is to continue along the idea of the blanket system that you mentioned and that I have been trying to create, because I have pretty much everything ready. Like you said, it is better if it is done this way, particularly if they have different ways of burning, and I do, so I will copy my FireCloak over each of the objects I want to burn and then simply create an animation for that object suitable for burnt, and I will also create different points For the FireCloak and set the position of the fire accordingly depending on what is burning. I think this is appropriate, considering that I know what all the flammable objects are and where they are and how many I have. It would be a different story if I didn't know that stuff. Thanks dude, you've definitely, given me a better understanding of what I'm doing!

Of course, if anyone else has a better idea, please reply.

Edit: By the way, those steps you mentioned in your Edit, are principles that I intend to follow. Thanks for sharing! :D
B
11
S
3
G
2
Posts: 36
Reputation: 1,811

Post » Mon May 01, 2017 2:19 am

No problem at all.

I fumble through this stuff just as much as the next guy... my ideas are probably not the most efficient way to deal with things, but it certainly helps get the job done via my way of thinking and seems pretty solid.

You can easily make the fire "spread" via a simple event "fire is overlapping X object/family" - then create events to control EXACTLY what happens when said object is on fire.

I would probably still suggest adding all flammable objects into a family (called flammable, or burnable, etc) then use that family to do the fire "spread". From there, reference each object individually once it's "on fire, IsBurning=1, etc" and create the effects or frame/animation changes as required.

~Sol
Tired of crappy file hosts that are crappy? Get DROPBOX - https://db.tt/uwjysXJF
Moderator
B
81
S
34
G
40
Posts: 3,031
Reputation: 30,422

Post » Mon May 01, 2017 2:25 am

I think I am definitely on the right track with this in accordance with your advice, SoldjahBoy. The only problem though is getting my head around families and how I can incorporate that in my project currently. I've read guides and watched videos, but I lack confidence in using them with what I'm doing. It might be because I feel like I have to do an overhaul. =[
B
11
S
3
G
2
Posts: 36
Reputation: 1,811

Post » Mon May 01, 2017 2:32 am

Nah it should be super easy to add a family for burnable items.

Just do to your project and in the right side pane, find families and right click -> add new family -> add all burnable objects to family -> name family "flammable" or something like that. Give the family some instance variables for things like "IsOnFire" or whatever is needed. These variables will reference the object only through it's family relationship and work separately to the objects actual instance variables, but the variable data can easily be transferred to the object itself.

Now make an event:
Fire overlapping "Flammable" (family)
-> "Flammable" (family) "isOnFire" = false ==> Set object on Fire (set "IsOnFire"=true)

Families are super easy to work with, and not as difficult as you perceive. The idea is to be able to affect many objects and instances of objects using one event. For another example if you had a bunch of enemies that are all different objects to each other, you can make a family called "enemy" and combine them into a single reference for say, when you shoot a bullet. Bullet collides with "enemy" then subtract health variable from whatever "enemy" the bullet hit. It saves you from haveing to make events like "bullet hits enemy 1 -> do this" then "bullet hits enemy 356 -> do this".

~Sol
Tired of crappy file hosts that are crappy? Get DROPBOX - https://db.tt/uwjysXJF
Moderator
B
81
S
34
G
40
Posts: 3,031
Reputation: 30,422

Post » Mon May 01, 2017 3:02 am

Hmm, I'll give this a go, but there is just one thing I am not sure about, and I think I can do it with families because I am sure I can set individual instance variables:

I have to be able to identify which Fire is what, because in my game, I have to be able to recognise that Fire1 and Fire2 are different. The reason being is because the player will get points for extinguishing Fires, but the player has to extinguish the entire Fire, so the entire Fire of Fire1 or the entire fire of Fire2 to get points. The game can create multiple Fires, so for each Fire that is created in the game, I have set a unique instance value called Fire_ID which is given to the Fire when it is created and when it spreads to other objects, I also assign the burning objects the same Fire_ID as the Fire that is burning it. This is to stop it conflicting with other fires. So the question is, even though all my flammable objects would be in a family, can they be set different Fire_IDs without changing the Fire_ID to all of the objects in the family?
B
11
S
3
G
2
Posts: 36
Reputation: 1,811

Post » Mon May 01, 2017 3:54 am

Ah yes well if you need that additional control over individual fires, then doing them as separate objects could prove a more flexible method :)

~Sol
Tired of crappy file hosts that are crappy? Get DROPBOX - https://db.tt/uwjysXJF
Moderator
B
81
S
34
G
40
Posts: 3,031
Reputation: 30,422

Post » Mon May 01, 2017 4:06 am

So in this case, doing families is not a good idea?

Sorry, I'm just a bit confused. xD
B
11
S
3
G
2
Posts: 36
Reputation: 1,811

Post » Mon May 01, 2017 4:38 am

Oh, not saying it's a bad idea at all... it all really depends on your requirements and how you want the game to work.

If you want fire spread to be simple, then using a family will help a lot for that type of thing. The difficulties will start to arise when you're defining whatever constitutes a "new fire" from the old fire. I guess only you really know exactly what you're wanting to achieve, so the methods used can often be specific to the problem :)

~Sol
Tired of crappy file hosts that are crappy? Get DROPBOX - https://db.tt/uwjysXJF
Moderator
B
81
S
34
G
40
Posts: 3,031
Reputation: 30,422

Next

Return to How do I....?

Who is online

Users browsing this forum: BadMario, stevenode and 6 guests