skip to content

In game physics, how does a trigger volume differ from a solid collider, and how do layer masks decide what collides or gets queried?

level: juniorimportance: should knowfreq 55%

answer

  1. detects, but does not push
  2. enter and exit events
  3. category and mask bits
  4. both sides of the pair must agree

basics

~20 s

A solid collider takes part in contact resolution, so bodies push against it; a trigger only detects overlap and reports enter and exit events. Layer masks filter which collider pairs are tested and which colliders a query may hit.

solid answer

~50 s

A **solid collider** generates contacts that the solver turns into pushes, so bodies cannot pass through it. A **trigger** is a shape flagged as non-solid: the broad and narrow phase still detect the overlap, but no contact reaches the solver; instead the physics system reports when a pair **begins** and **ends** overlapping (often also while it stays). Triggers drive checkpoints, pickup zones, damage areas and door sensors. **Layers** give each collider a category and a mask of categories it interacts with; in the common symmetric scheme a pair is tested only if each side's mask includes the other's category, and some engines use a central table of layer pairs instead. Queries take their own mask, a flag for whether triggers count, and an ignore list. Filtering before the narrow phase also saves work, because rejected pairs are never tested exactly.

code

pseudocode · 9 lines
pseudocode
function shouldTestPair(a, b):
    if a.group != 0 and a.group == b.group:
        return a.group > 0          // positive group: always collide; negative: never
    return (a.category & b.mask) != 0 and (b.category & a.mask) != 0

function pairResponse(a, b):
    if a.isTrigger or b.isTrigger:
        return OVERLAP_EVENTS_ONLY  // no contacts reach the solver
    return SOLID_CONTACT

go deeper

for a junior

Recall that a trigger detects overlap and raises enter and exit events without pushing anything, while a solid collider blocks. Name a few uses of each.

for a middle

Explain how begin and end events come from comparing overlaps between steps, and how categories, masks and query filters decide which pairs and hits exist.

for a senior

Diagnose filter bugs from symptoms: self-hits at zero distance, shots stopped by sensors, one-sided mask edits, missed fast triggers, and unsafe edits inside callbacks.

for a principal

Decide a project-wide layer scheme early: a small fixed set of categories with documented intent, owned by one team, because ad hoc layers per feature run out and break interactions.

## Solid colliders and triggers Every collider in a physics world is a shape attached to a body or to the static world. What differs is what happens when another shape overlaps it. | | Solid collider | Trigger volume | |---|---|---| | Detected by broad and narrow phase | yes | yes | | Contacts sent to the solver | yes | no | | Effect on bodies | they are pushed apart | they pass through | | What gameplay receives | collision or contact events | overlap begin and end events (often also a "stays" event) | | Typical uses | walls, floors, crates, characters | checkpoints, pickups, kill zones, door sensors | A **trigger** is therefore a sensor: it uses the collision pipeline to find overlaps and then deliberately skips the response. ## How trigger events are produced The physics system keeps a record of which pairs were overlapping last step. After each step it compares that record with the new overlaps: 1. a pair that overlaps now but did not before produces a **begin** (enter) event; 2. a pair that overlapped before and still does may produce a **stay** event; 3. a pair that overlapped before but no longer does produces an **end** (exit) event. Consequences worth knowing in an interview: - events are normally collected during the step and **dispatched afterwards**, so destroying or moving bodies inside a callback is safe only if the engine defers it; many require you to queue such changes; - detection happens at discrete steps, so a fast object can cross a thin trigger between two steps and produce no event at all (the same tunnelling problem continuous collision detection addresses for solid contacts); - pairs of two static colliders are usually never tested, and engines differ on which body types must be present for a trigger to fire, so check the rules of the engine you use rather than assuming. ## Layers, categories and masks Large games have many kinds of collider: level geometry, characters, projectiles, debris, cameras, sensors. Most of these kinds should never interact, and filtering them out early saves narrow-phase work and prevents bugs. The common scheme gives each collider: - a **category**: one bit naming what it is (for example `WORLD`, `PLAYER`, `ENEMY`, `PROJECTILE`, `DEBRIS`); - a **mask**: the set of category bits it is willing to interact with. In the **symmetric** rule a pair is tested only when both sides agree: `(a.category & b.mask) != 0` and `(b.category & a.mask) != 0`. If either side excludes the other, the pair is skipped. Some engines instead keep a central table that says, for each pair of layers, whether they collide; the effect is the same. Many also support a **group** override so, for example, the parts of one ragdoll never collide with each other. ## Query filters Queries do not use the collider's own mask; they take a filter of their own: - a **mask** of the categories the query may hit (a ground check hits `WORLD` and `PLATFORMS`, not `DEBRIS`); - whether **triggers** count as hits, often off for gameplay queries so a pickup zone does not block a line of fire; - an **ignore list**, most importantly the querying character's own collider, which otherwise makes a cast that starts inside it report a hit at zero distance; - in some engines a callback that accepts or rejects each candidate, for rules masks cannot express (ignore teammates, ignore one-way platforms from below). ## Common bugs - A projectile hits its shooter on the frame it spawns, because the shooter's collider was not excluded. - A bullet hits a pickup trigger, because the line-of-fire query includes triggers. - One side's mask was updated and the other's was not, so a pair that "should" collide never does under the symmetric rule. - Debris collides with everything and floods the solver with pairs that no player will ever notice.

  • Why should a line-of-fire query usually exclude triggers?
    Triggers are invisible sensors such as pickup zones and checkpoints. If the query counts them, a shot or an interaction ray stops at an invisible volume instead of the wall or enemy behind it. Excluding triggers by default, and opting in only for queries that look for sensors, avoids that class of bug.
  • Why can a fast pickup be missed by a thin trigger volume?
    Overlap is checked once per simulation step. If the object moves farther in one step than the trigger is thick, it can sit before the trigger in one step and past it in the next, so no overlap is ever recorded. Thicker triggers, a swept check for that object, or more steps fix it.

  • A trigger is a solid collider with very soft contacts
  • A trigger reports nothing unless you poll it each frame
  • Under category-and-mask filtering, one side allowing the pair is enough
  • Layer masks only affect queries, never which bodies collide
  • Destroying a body inside a trigger callback is always safe