Menu
Lumberyard
Developer Guide (Version 1.12)

Creating Explosions

The function SimulateExplosion is used to simulate explosions in a physical world.

The only effect of explosions inside the physics system are impulses that are added to the nearby objects. A single impulse is calculated by integrating impulsive pressure at an area fragment multiplied by this area and scaled by its orientation towards the epicenter.

Impulsive pressure has a falloff proportional to 1/distance2. If distance is smaller than rmin, it is clamped to rmin.

impulsive_pressure_at_r is the impulsive pressure at distance r.

SimulateExplosion can optionally build an occlusion cubemap to find entities occluded from the explosion (nOccRe_s should be set to a non-zero cubemap resolution in one dimension in this case). First, static entities are drawn into the cubemap, and then dynamic entities of the types specified in iTypes are tested against the map. Thus, dynamic entities never occlude each other.

Passing -1 to nOccRes tells the function to reuse the cubemap from the last call and process only the dynamic entities that were not processed during the last call. This is useful when the code that creates the explosion decides to spawn new entities afterwards, such as debris or dead bodies, and wants to add explosion impulses to them without recomputing the occlusion map.

Due to the projective nature of the cubemap, small objects very close to the epicenter can occlude more than they normally would. To counter this, rmin_occ can specify linear dimensions of a small cube that is subtracted from the environment when building the occlusion map. This crops the smaller objects but can make explosions go through thin walls, so a compromise set of dimensions should be used.

nGrow specifies the number of occlusion cubemap cells (in one dimension) that dynamic entities are inflated with. This can help explosions to reach around corners in a controllable way. After a call has been made to SimulateExplosion, the physics system can return how much a particular entity was affected by by calling IsAffectedByExplosion.

IsAffectedByExplosion returns fraction from zero to one. The IsAffectedByExplosion function performs a lookup into a stored entity list; it does not recompute the cubemap. The explosion epicenter used for generating impulses can be made different from the one used to build a cubemap. For example, you can create explosions slightly below the ground to make things go up instead of sideways. Note that this function processes only parts with geom_colltype_explosion.