# 10. Explosions¶

This page details the physics of explosion and explosive weapons, along with some speedrunning tricks that arise of out these aspects of the game. Familiarity with the health and damage system is assumed (see Health and damage).

Fig. 10.1. A powerful explosion created by a mortar strike in We’ve Got Hostile that gibbed a human grunt in one hit and inflicted some damage to the player from a distance.

## 10.1. General physics¶

An explosion is a phenomenon in Half-Life that inflicts damage onto surrounding entities. An explosion need not be visible, though it is normally accompanied with a fiery visual effect. We may describe an explosion in terms of three fundamental properties. Namely, as illustrated in Fig. 10.2., an explosion has an origin, a source damage, and a radius.

Fig. 10.2. Illustration of the three main properties used to describe an explosion, namely the origin at the centre of the explosion, the source damage at the origin, and the radius of explosion. Here, it is assumed that nuking (see Nuking) is not done, and so the damage falls off linearly with distance from origin.

Suppose an explosion occurs. Let be its source damage and its radius, as shown in Fig. 10.2.. Suppose there is an entity adjacent to the explosion origin. From gaming experience, we know that the further away this entity is from the explosion origin, the lower the damage inflicted on this entity. In fact, the game only looks for entities within a sphere of radius from the explosion origin, ignoring all entities beyond. In the implementation, this is achieved by calling UTIL_FindEntityInSphere with the radius as one of the parameters.

Assume the entity in question is within units from the explosion origin. First, the game traces a line from the explosion origin to the entity’s body target. Recall from Entities that the body target of an entity is usually, but not always, coincident with the entity’s origin. Then, the game computes the distance between this entity’s body target and the explosion origin as . The damage inflicted onto this entity is thus computed to be

(10.1)

Observe that the damage inflicted attenuates linearly with distance, also illustrated in Fig. 10.2., and not with the square of distance as is the case in the real world. This process is repeated with other entities found within the sphere.

Interestingly, the computed distance may not equal to the actual distance between this entity and explosion origin. In particular, if the line trace is startsolid, then the game computes . As a result, the damage inflicted on the entity is exactly the source damage of the explosion. Indeed, all entities within the sphere will receive the same damage.

The case where the line trace is startsolid is seemingly impossible to achieve. Fortunately, this edge case is not hard to exploit in game, the act of which is named nuking as will be detailed in Nuking. The key to understanding how such exploits might work is to observe that the explosion origin may not coincide with the origin of the entity just before it detonates. The exact way the explosion origin is computed depends on the type of entity generating the explosion.

## 10.2. Explosion origin¶

Explosions are always associated with a source entity. This entity could be a grenade (of which there are three kinds) or an env_explosion.

Denote the position of the associated entity. When an explosion occurs, the game will trace a line from to . The exact coordinates of these two points depend on the type of the associated source entity, but they are always, in one way or the other, offset from the source entity’s origin. In general, we call the end position from the line trace. If the trace fraction is not 1, the game will modify the position of the source entity. Otherwise, the position will not be changed, making .

Assuming the trace fraction is not 1, the new position of the source entity is computed to be

(10.2)

All numerical constants are hardcoded. Call the coefficient of the pull out distance, as per the comments in the implementation in ggrenade.cpp. This is so named because if the source entity is a grenade, it is typically in contact with some plane or ground when it explodes. By modifying the origin this way, the source entity is being pulled out of the plane by that distance. Remarkably, this distance depends on the source damage of the explosion. For instance, MP5 grenades create explosions with a source damage of , therefore MP5 grenades are pulled out of the plane by 45.6 units at detonation.

Subsequently, the source entity will begin to properly explode. The physics driving the rest of this event has been described in General physics. Most importantly, the explosion origin is set to be where is the axis unit vector. Observe how the is added to the entity’s origin, the purpose of which is to pull non-contact grenades out of the ground slightly, as noted in the comments. In the implementation, the addition of this term is done in the function responsible for applying explosive damage, namely RadiusDamage. Since all explosion code invoke this function, this term is always added to the origin for any explosion that happens.

A contact grenade is a type of grenade which detonates upon contact with a solid entity. This includes the MP5 grenades and RPGs.

Fig. 10.3. Illustration of a contact grenade striking a surface and computing position of the the explosion origin . The line is tangent to the trajectory at the final position.

Let be the origin of a contact grenade moving in space. Assuming the map is closed, the grenade will eventually hit some entity and then detonate. Denote unit vector the normal to the plane on the entity that got hit. Note that at the instant the grenade collides with the plane, its position will be on the plane. Thus at this instant, let be the velocity of the grenade.

Then, the start and end points of the line trace are given by

Here, is 32 units away from the position of the grenade at collision, in the opposite direction of its velocity. And is 32 units away from that position, but in the direction of the velocity. It is easy to imagine that, more often than not, the end position of the line trace will coincide with the grenade position. This line trace will also rarely be startsolid. This is because the grenade has to pass through open space before hitting the plane, and is approximately one of the grenade’s past positions.

Timed grenades are grenades that detonate after a specific amount of time. This includes hand grenades, which explode three seconds after the pin is pulled.

Fig. 10.4. The handgrenade is the most common example of a timed grenade.

Denote the origin of a timed grenade. At detonation, the grenade may or may not be lying on a plane. Since the grenade could well be resting on the ground with zero velocity, it does not make sense to use the velocity in computing the start and end points for the line trace. Instead, Valve decided to use to offset those points from the grenade origin. So, we have

Now, is simply 8 units above the grenade and is 32 units below the grenade. This means that there is a greater chance that this line trace is startsolid and also that the trace fraction is 1. The former can occur if there is a solid entity above the grenade, while the latter can occur if the grenade is sufficiently high above the ground.

### 10.2.3. Explosions by env_explosion¶

An env_explosion is an invisible entity that can explode, which may be created by monsters, explosive func_breakable creates, or map designers.

Denote the origin of the env_explosion. Then

Notice that the and for this entity type is similar to that of a timed grenade.

### 10.2.4. Tripmines¶

A tripmine is a grenade that detonates when it is “killed”. In this context, a tripmine can be killed by some external damage or by something blocking the beam.

Denote the origin of a tripmine, and the tripmine’s unit forward vector (unrelated to the player’s unit forward vector). Then we have

The unit forward vector is very well defined in the game, because it is parallel to the beam.

Compared to a timed grenade or an env_explosion entity, the is located deeper beneath the entity.