PcoWSkbVqDnWTu_dm2ix
We use cookies on this site to enhance your user experience

Fire Simulation Library

Fire Simulation Library

Jul 02 2018, 4:38 PM PST 5 min

The Fire Simulation Library is a module you can include in your game to simulate temperature. If parts in your workspace are set on fire, the temperature will increase and spread to other parts.

Setup

The library is hosted on the Roblox Wiki account as a ModuleScript. It can be included by requiring its assetId: 437793007

local fireModule = require(437793007)

To save on performance, the module does not register parts in the Workspace automatically. You can use the RegisterPart function to indicate which parts in your game you want to be affected by temperature changes. When you register a part with this function, the function will recursively register all the descendants of that part as well. You can also register individual parts with the RegisterPart function.

A simple approach to registering parts is to have a Folder in your workspace that contains all of the flammable parts and to call RegisterParts on that folder.

local fireModule = require(437793007)
fireModule:RegisterParts(game.Workspace.FireParts)
While you can call RegisterParts on the `Workspace` itself, this is only recommended in small games with low part counts.

Fire Tools

While you can script your own ignition systems, several fire tools are available by default. These can be taken here, or inserted with InsertService.LoadAsset with the ID 437821587. You can put these tools in the Workspace or StarterPack as normal. These tools include a Fire Extinguisher and Flamethrower.

Both of these tools will fire in the direction of the player’s character. They are easiest to use with either Mouse Lock or First Person view.

The effect of the tools is not instantaneous. It usually takes a few simulation steps to ignite or extinguish a part. Keep in mind the larger the part the harder it is to change the temperature.

Methods

If you want to control the ignition manually with a script, you can do so with the following functions:

Method Description
SetPartTemperature(BasePart part,Number temperature) Sets the temperature of a registered part
GetPartTemperature(BasePart part) Gets the temperature of a registered part. Returns nil if part is not registered
SetVoxelTemperature(Number x,Number y,Number z,Number temperature) Sets the temperature of specified voxel. X, Y, Z values are given in world coordinates
GetVoxelTemperature(Number x,Number y,Number z) Gets the temperature of specified voxel. X, Y, Z values are given in world coordinates
SetConfiguration(String name,Variant value) Sets the value of specified configuration
GetConfiguration(String name) Gets the value of specified configuration
SetMaterialConfiguration(Enum.Material material, String name, Variant value) Sets the value of specified material configuration
SetMaterialConfiguration(Enum.Material material, String name) Gets the value of specified material configuration
RegisterParts(Instance group) Registers and initiates simulation on group and all descendants of group
GetRegisteredParts() Returns a list of all parts registered in the simulation
RegisterPart(Instance part) Registers an individual part in the simulation
IsPartRegistered(Instance part) Returns true if the part is registered in the simulation, otherwise returns false
UnregisterPart(Instance part) Removes an individual part from the simulation
UnregisterAllParts() Clears all parts from the simulation
ClearVoxels() Resets all voxels to ambient temperature

Configuration Options

The module has several global configurations that can be get and set with GetConfiguration and SetConfiguration respectively.

Configuration Description
AmbientTemperature The temperature all parts start at, and that all parts will return to when there is no source of heat
ConductionSpeedTouch The speed at which heat is transferred between touching parts
ConductionSpeedWelded The speed at which heat is transferred between attached parts
ConvectionSpeed The speed at which heat is transferred to and from the surrounding air
MaterialStrength The heat resistance of the materials. This value changes how long it takes for a part to completely burn out
DoDebug When true, the library will output debugging messages. Off by default
RecalcChance Chance to recalculate parts and voxels that haven’t had recent temperature change
DeltaTVoxelTransferThreshhold Voxels above this temperature will simulate every step, otherwise voxel will rely on random recalculation to update
DeltaTPartTransferThreshhold Parts above this temperature will simulate every step, otherwise voxel will rely on random recalculation to update
TempBeginGlow Temperature at which parts begin to glow
TempToMaxGlow Temperature range above TempBeginGlow in which the part isn't quite fully glowing yet
BreakAtPercentBurned Percentage when parts will turn black and break joints
VoxelCenterTemperatureWeight Weight of current voxel when calculating average temperature per voxel
VoxelUpTemperatureWeight Weight of above voxel when calculating average temperature per voxel
VoxelDownTemperatureWeight Weight of below voxel when calculating average temperature per voxel
VoxelSideTemperatureWeight Weight of adjacent voxels when calculating average temperature per voxel

In addition to the global configurations as seen above, each part material has several configurations. These can be get and set with GetMaterialConfiguration and SetMaterialConfiguration.

Configuration Description
BurnTemp Temperature of the flame the material produces. This is the temperature a part tries to reach when it burns
IgnitionTemp Minimum temperature required to set part on fire
IsFlammable If set to false, the material will never set on fire
SpecificHeat Determines how difficult it is to change the temperature of a given material

Sample Code

To light all of the flammable parts in a place on fire, simply set their temperatures sufficiently high:

local fireModule = require(437793007)
fireModule:RegisterParts(game.Workspace.FireParts)

for _, part in ipairs(fireModule:GetRegisteredParts()) do
  fireModule:SetPartTemperature(part, 1000)
end
Tags:
  • fire
  • simulation.
  • physics
  • gameplay