Unity Fire Propagation System (C#)
A real-time fire propagation system for outdoor environments used within games developed using Unity, the system is based upon the framework that I developed whilst at Bournemouth University for my dissertation.
The system is a small collection of C# scripts that allows developers to add fire to an outside terrain environment. Designed to be easily integrated into a new or existing project, giving full control to developers to be able to define the appearance and behaviour of the fire. Fire is able to propagate over terrain and any other object that has been set as a flammable object, destroying objects encountered and even leave scorch marks behind where the fire has been.
Feature list:
Since being released its had more than 11,200 downloads on the Unity Asset Store!
Get it from the Unity Asset Store: https://assetstore.unity.com/packages/tools/fire-propagation-92187
The system is a small collection of C# scripts that allows developers to add fire to an outside terrain environment. Designed to be easily integrated into a new or existing project, giving full control to developers to be able to define the appearance and behaviour of the fire. Fire is able to propagate over terrain and any other object that has been set as a flammable object, destroying objects encountered and even leave scorch marks behind where the fire has been.
Feature list:
- Real-time physically based fire propagation simulation
- Affected by the wind
- Fire propagates over terrain and flammable objects
- Total control over fire appearance
- Easy to use with minimum requirements
- Demo included
Since being released its had more than 11,200 downloads on the Unity Asset Store!
Get it from the Unity Asset Store: https://assetstore.unity.com/packages/tools/fire-propagation-92187
Use and Code Samples
To allow for easy integration the requirements are minimum and if a terrain is already set up most of the requirements would have been met. Requirements:
- 1 Terrain GameObject (with two terrain textures and grass details).
- 1 Fire Manager, child of the Terrain object.
- A GameObject with a FireIgniter script attached to create fires.
- 1 Prefab with Particle Systems, to be used to create fires.
- Windzone (Optional, recommended).
The fire propagation simulation uses a grid-based approach for terrain and a node system for GameObject's within the scene, which the cells within a grid can interact with.
At the heart of the system is the Fire Manager, the Fire Manager handles settings that are global across all fires in the scene. To fully understand how to use the Fire Manager, some understanding of the propagation simulation is required. The propagation is simulated in a grid which each cell having different fuel values based on the terrain textures that have been set, taking into account variables such as air temperature and ground moisture. Each cell is heated up to ignition temperature, then burns until there is no more fuel left in the cell then goes out. There is a range of different settings that can be set and modes enabled for the simulation to perform additional actions, such as replacing terrain textures or removing burnt grass from the terrain. |
When the fire is propagating on the terrain it will detect any fire chain within heating distance and will start to heat up the ignitable object the fire chain belongs to. The ignitable object can either be destroyed or replaced with another object once all of the fire nodes have been consumed by the fire. A Fire Node Chain is mostly a container for all for the Fire Nodes an
object has and to set shared fuel values between all contained nodes. Fire Node's allow for each node to have its own fuel value, which is useful for an object like a tree where the fuel from the base of the trunk to the top of the tree could change. They also have an array of “linked” nodes, fire will propagate an ignitable object using these links. |
The appearance if any fire is under the developer's direct control, the only thing the fire propagation simulation does is provide the ability to toggle when particle systems contained within the Fire Prefab should be active or inactive. There are three internal states, Heat Up, Ignition and Extinguish. Set these arrays to match the number of particle systems in the Prefab, for each state all developers need to do is tick the particle systems they want to be active. When a cell is being heated up the Heat Up state it active, when the ignition temperature has been reached the internal state is Ignition. The internal Extinguish state is set by the Visual Extinguish Threshold in the Fire Manager, the smaller the threshold value to longer the Ignition state will last. The threshold is percentage based on the about of fuel available to the fire.
|