Game Development Community

Gasoline, Terrain, Flame Physics

by Michael Perry · in Torque Game Engine · 07/31/2007 (9:03 am) · 4 replies

Greetings all!

I got a "toughy" of a challenge for the community (myself included). The concept is simple enough, but the implementation has me pretty stumped:

Goal:
  • Applying flammable property to terrain and objects dynamically[li]Igniting flammable objects[li]Flame physics(grows, spreads, and eventually dies out)
Possible Execution:
Player picks up gasoline cannister. Player starts pouring and walking. Terrain sections and objects that are soaked in gasoline are now flammable. Constant pouring of gasoline creates pool (greater combustion). Player shoots/ignites portion of gasoline trail. Gasoline trail ignites and fire spreads. Pretty effects follow. Apply damage (or damage over time) to applicable objects. Fire eventually dies out.

My Thoughts:
My first thought is to modify an AI package from an old project of mine. The purpose of the package was to create important nodes and paths in a mission without using the WorldEditor. The user would drop in the world as a player. When a special key was pressed (ex. F4), the player would start dropping nodes in the world every few meters. When F4 was pressed again, the nodes were recorded, paths were created, and the mission was saved. Now, I suppose this would work for creating a path of fire, and bypass the need for grabbing terrain data at a given location, but I'd like to hear your thoughts on making this work in a less "hacky" way.

#1
07/31/2007 (9:56 am)
Hmmm.... I have seen this effect in games like Postal 2..


The last goal: " Flame physics(grows, spreads, and eventually dies out)"

Made me immediately think of P. Dana's BitShifter/FlashBios game where the terrain would become "infected" and that infection could spread depending on certain factors. The infection could be 'cleaned up' (an integral part of the game).

As far as the physics, just guessing but I would try a combination of projectile and particle effects, making the projectile arc out like a liquid, setting flags on terrain/objects as it hits them.

A dynamic flag of "isFlammable" would be an easy way to set/check flammability.
#2
07/31/2007 (10:02 am)
Actually, I think the idea of dropping nodes while pouring the gasoline would work well. Instead of dropping a node every meter or two maybe do the drops based on time. Say, every 0.5 - 1.0 seconds drop a node. That node could have an AFX effect attached to it with a default radius and for every node within a certain radius of another we exponentially increase that radius to create a growing pool of gas.

Of course, the downside of it comes from what happens when pouring downhill. Perhaps a Zodiac could help there.
#3
08/01/2007 (2:03 pm)
What I'd really like to see is terrain that's flammable even without having been drenched with petrol. So for example, youhave a rocky hillside beside a grassy plain. You pour a line of gasoline down the hillside and light it at the top. The fire burns the gasoline on the rock, but when it reaches the grass, the terrain itself catches fire. The fire spreads over the whole area of grass texture, stopping at a river or whatever. Then the real beauty would be modifying the texture so that all that area of grass was now blackened ;).
#4
08/04/2007 (11:07 am)
I'd think you could still use your node concept while having the terrain types ignite without gasoline.

Something like (numbers just a guess):
If dropping gas, place flamable node there with value 5.
- pick numFlowSpots = random(5,15) spots within .5 meters of it.
-- For each numFlowSpots, if it's lower or same height then original, pick a random numFuelShifted = random (.1,2). If there's an object there (do a raycast looking for items, interiors, players, vehicles), then handle each differently
-- Decrease the original node by numFuelShifted (keep it at least .1), add a new node here with value numFuelShifted.
--- Recursively call the original function

This should give you a randomly spreading fuel set of nodes that seems halfway realistic. You could improve it by:
- For each type of terrain, have a FrictionOfLiquid setting
-- The higher the friction of Liquid, the higher the random amount that moves from the source to the next node
- The higher the difference in terrain elevation, the higher the amount shifts. (thus it flows down much faster on hills).
ex: You could make the function above be numFuelShifted = random (.1,%FrictionOfLiquid*%HeighDifference)

You could even get really fancy, and then make vehicles, players, or any type of objects that are moving start dropping fuel off in the same manner. Thus, poor gas on a car, if it drives away the wheels leave a train of flamable nodes.



Next, you could have a second Flammability setting for each terrain type. When you drop a match, or shoot a flare, or shoot a bullet (that hits concrete and sparks... most bullets don't automatically ignite gas - ask the MythBusters), have it start an ignite function.

- Use the terrain (or object's) Flammability setting as a base value. Search through your gas nodes for a node within .1 meter, and add those to the base setting for this location.
- If Random(.1,1) < base value, you've got a flame
- Spawn a flame here that will go out in a few seconds. Apply damage to everything here. If big enough, spawn some smoke. Decrease this gas node's value by .3.
-- Add a few gas nodes close by using the process up top, but with (base value - 1) flamability
- Search through your gas nodes, find all within (.1 meter * base value). Thus, bigger flames spread farther. Ignite those, and repeat the process.


This should give you terrain that spreads, and by tweaking all the variables, you could simulate wild fires, as well as have some pretty cool gas spills.

Things to watch out for:
- You might pour gas on top of a vehicle. It drives off, those nodes are still hanging in space.
-- You might try making them items, so they fall and bounce around. Probably too resource intensive though.
-- Other possibility, when you're looking at the node, check if it's still on top of something, if not move it to the terrain.

- Gas might fall off a cliff, and then your flame train miraculously jumps down 50 feet and continues.
-- Solution, Have ignition check the distance in X,Y, and Z, and not spread if the total distance is > the amount

- Too computationally intensive. That's a lot of things recursively building nodes and searching through nodes
-- Try to build a geo-based tress structure for storing locations, so that searching through it is much faster
-- Play with the variables, you might have to trade off realism for speed
-- You could always make it dynamic, based on the speed of the processor
-- Make your flame and smoke animation less detailed, or have less particles


OK, that's all of my thinking for today. Back to read Harry Potter.