skip to content

In a firefight, several NPCs run to the same cover spot and some pick cover that leaves them exposed; how should tactical cover selection score positions?

level: seniorimportance: should knowfreq 50%

answer

  1. generate, filter, score, claim
  2. hard filters before soft scores
  3. protected from where the threat is
  4. cheap tests first, rays last
  5. one point, one occupant

basics

~20 s

Generate candidate points, discard any that fail hard tests such as unreachable, already claimed or not shielded from the current threat, score the rest on weighted preferences like distance, firing angle and danger, then claim the winner so others pick elsewhere.

solid answer

~50 s

Cover selection is a query: **generate** candidates (authored cover points or points sampled along obstacles near the NPC), **filter** with hard rules, **score** the survivors, **select** the best and **claim** it. The two symptoms have different causes. Everyone choosing one spot means identical inputs and no **reservation**: the fix is to claim the point on selection, penalise points near other NPCs' claims, and release claims on death, departure or timeout. Exposed cover means protection was tested against the wrong thing: only the cover's facing, an old threat position, cover lower than the NPC's crouched head, or a route to it across open fire. The fix is a ray from the threat's eye to the NPC's crouched head at that point, which must be blocked, plus a clear ray from the peek position, re-checked when the threat moves. Run the cheap filters first and the rays only on the top few candidates.

go deeper

for a junior

Recall the pipeline: generate candidate points, filter out impossible ones, score the rest, pick the best and claim it.

for a middle

Explain the difference between hard filters and soft scores, how the facing test and the protection ray differ, and why claims must be released.

for a senior

Diagnose shared and exposed cover from playtest symptoms, budget the rays for a query, and decide when an NPC in cover should re-evaluate.

for a principal

Decide whether cover selection is shared infrastructure every enemy type uses, and set how much authored cover data versus runtime sampling the content pipeline maintains.

## The query pipeline Choosing where to take cover is a **position query**: rather than hard-coding a spot, the NPC asks "of all nearby places, which is best for me right now?" A dependable shape is: 1. **Generate** candidates: authored cover points placed by designers or tools, or points sampled along the edges of walkable space next to obstacles. 2. **Filter** with hard rules that disqualify a point outright. 3. **Score** the survivors with weighted preferences. 4. **Select** the highest score. 5. **Claim** the point so no other NPC takes it. Splitting **hard filters** from **soft scores** keeps the result explainable: a point is either impossible or merely less good. ## Hard filters and soft scores | Kind | Example | Typical cost | |---|---|---| | Hard filter | Reachable on the navigation graph | Path query | | Hard filter | Not claimed by another NPC | Lookup | | Hard filter | Cover faces the threat, within some angle of its direction | Dot product | | Hard filter | Threat's line of sight to the crouched NPC is blocked | Ray per threat | | Soft score | Short distance from the NPC | Arithmetic | | Soft score | Threat within the NPC's preferred weapon range | Arithmetic | | Soft score | Low danger on an influence map; good flanking angle | Lookup | The score is a weighted sum of normalised terms, `score = sum(w_i * s_i)`. Debug drawing each candidate's score and the filter that rejected it is the fastest way to see why a choice was made. ## Why everyone picks the same spot NPCs that run the same query from nearly the same place against the same threat get the same answer. Fixes, in order of importance: - **Claim** the selected point at once, and have later queries treat claimed points as unavailable. - **Penalise** points within a few metres of other claims so a squad spreads out. - **Release** claims on death, on leaving the point, and after a timeout if the NPC never arrives; stale claims silently block good cover. - When several NPCs query in the same frame, process them one after another so the second sees the first's claim. ## Why chosen cover fails to protect The facing test, a dot product between the cover's normal and the direction to the threat, is necessary but not sufficient. Common gaps: - **No protection ray**: the cover faces the right way but is too low, or a gap lets the threat see the NPC's crouched head. - **Stale threat position**: protection was tested against where the threat was when the query ran, and the threat has since flanked. - **Several threats**: the point hides the NPC from one enemy and exposes it to another. - **Exposed route**: the point is safe, but reaching it means crossing open ground in the threat's view. Testing a ray from the threat's eye position, using the threat's position as the NPC has perceived it, to the NPC's crouched head at the candidate, which must be blocked, together with a clear ray from the standing or peeking pose so the NPC can fire back, catches the first case. Re-checking the occupied point's protection periodically, and moving only when a new point beats it by a clear margin, catches the second without constant swapping. ## Keeping it affordable Rays dominate the cost. With 50 candidates, two rays per candidate per threat and 3 threats, testing everything is 300 rays; scoring cheaply first and ray-testing only the top 10 is 60. Queries can also be time-sliced across frames, since an NPC deciding in 100 milliseconds rather than 16 is rarely noticeable to the player. ## Diagnosing a bad choice When a tester reports a strange cover choice, work from evidence rather than from weights: 1. Record the query: every candidate, the filter that rejected it, and each survivor's score terms. 2. Check whether the chosen point passed its protection ray when the query ran and whether it still passes; if it no longer does, the threat moved and the re-check is missing or too slow. 3. Check the claims for stale reservations that hid better points. 4. Only then adjust weights, against a set of saved situations, so that fixing one case does not break another.

  • When should a claimed cover point be released?
    When its occupant dies, leaves it, or chooses another point, and after a timeout if the NPC never arrives, for example because its path was blocked. Without the timeout and death cases, claims leak and the best cover in a room stays reserved for nobody, which looks like NPCs inexplicably ignoring obvious cover.
  • When should an NPC already in cover look for a new point?
    When a periodic re-check shows the threat can now see it, when a new threat appears on its flank, or when a danger stimulus such as a grenade lands nearby. To avoid hopping between two similar points, require a new point to beat the current one by a clear margin before moving.
  • Why ray-test only the best few candidates instead of all of them?
    Rays are the expensive part. Cheap filters and scores order the candidates first; the ray tests then run from the top until a point passes, or on a fixed top few. If the best-scoring point fails its protection ray, the next one is tried, so quality barely changes while the ray count drops several-fold.

  • Pick the nearest cover point; distance alone is enough.
  • If the cover faces the threat, it must block the threat's line of sight.
  • Random jitter on scores reliably stops NPCs sharing a point.
  • Ray-test every candidate against every threat before any cheap filter.
  • Once chosen, a cover point stays valid until the NPC dies.
  • Claims never need releasing; NPCs will pick other points anyway.