How NetWars Works Chapter 6 of 13, plus appendices

6. Combat and collisions

Lasers, missiles and ramming: how a hit is detected, what it costs, and the surprising shapes of the "hit zones" that come from simple box tests. Distances are in world units, speeds in units per frame (chapter 3).

Your laser

Firing

The hit test: a box around the shot

Each frame, after the shot moves, it is tested against possible targets. The test is a box in the shot's own frame (its forward, right and "up" axes, copied from your ship when it was fired): the target's centre must be within ±512 units along the shot's flight, and within a sideways half-width of ±192 units (big targets: aliens, pods, ships) or ±96 (small ones: missiles, satellites) along the other two axes. A first rough check against a ±512 cube in world axes saves time and slightly trims the box's corners.

Your shot (from above, flying right) box: 1024 long × 384 wide (× 192 for small targets) moves 1024 + your speed per frame Alien shot (from above, flying right) slab: 512 long, 2048 wide (its right axis), 512 high moves 1024 per frame: can jump over you Same scale in both drawings: 50 px = 512 units.
The shapes the two kinds of laser test. Your shots test a long, narrow box; alien shots a short, wide slab.

What a shot can hit, in order

ModeTargets, tested in this orderEffect
single player1. aliens−1 hit point, −2 while you have extra fire power left; at 0 the alien explodes and you get its points (100–400)
2. enemy missilesdestroyed, 25 points
3. podsdestroyed (friendly fire, no points, no message)
4. your satellitedestroyed, no points
multiplayer1. other players' ships (cloaked ones too)reported to the victim (below); +50 points for you per hit
2. other players' satellitesreported to the owner, who explodes it; no points
3. your satellitedestroyed

The first hit ends the shot (in single player); the shot then shows a small expanding red ring for 7 frames at the hit point. Objects that are already exploding (dying aliens, missiles, pods) cannot be hit, cannot ram and cannot be locked onto.

Quirks of the laser

Alien lasers

Quirk

The slab is only 512 units deep, but the shot moves 1024 units per frame. A shot aimed straight at you therefore passes through without a hit about half the time D (a pass-through was observed, runtime #27). And like yours, an alien shot moves before its first test: if you are less than about 768 units in front of the alien that fires, its shot never hits you D.

Missiles

Locking on

Your missiles (single player only, Enter or Caps Lock) need a target. After the aliens move each frame, every live alien is checked against a "lock window": it must be in front of you and within ±384 units of your line of sight, both sideways and up/down. Every alien that passes is marked, and the sight turns into the four-triangle bracket.

This window is a square beam of fixed width along your view direction, not a cone: at 16,000 units it reaches only about 1.4° off your line of sight (2.7° across), at 1000 units about 21° (42° across), and very close it covers almost everything in front of you, even outside the screen (an alien never drawn, 70° to the side, was locked and killed in a test run, runtime #34) D.

you lock window: ±384 units, any distance dashed: the edge of the screen's view, for comparison
Seen from the side, not to scale: near you the beam is wider than the view, far away it is a thin line.

Your missile

Enemy missiles

Pirate's missileCommander's missile
speed400, constant400; brakes by 12.5 per frame down to 50 while you are behind it, speeds up again when aimed
turn8 steps (1.4°) per frame32 steps (5.6°) per frame
gives upwhen about 16,000 units from younever

Ramming and other contacts

"Touching" means every coordinate difference is below about 256 units (ships, aliens and pods; 128 for satellites), i.e. the renderer's display exponent is 7 or more, and you are not in the 8 frames of bump immunity after the last collision (chapter 5).

ContactEffect
you and an alien (while you have shields)you lose 1 shield, light-green flash, bump (chapter 4; no bump if it was your last shield); the alien loses 1 hit point and may explode, but a ram kill gives no points
you and another player's ship (cloaked or not)you lose 1 shield, light-green flash and bump (none of these if it kills you); each machine decides this for itself and tells nobody
you and a satelliteyou collect it (chapter 7)
you and a podnothing
alien and alien, alien and podnothing (except an alien reaching the pod it is after, chapter 7)

Shields, damage and death

Multiplayer: the shooter decides

In multiplayer no machine simulates anybody else's weapons for real. The rules (the network side is chapter 8):

  1. The shooter's machine decides every hit. Its own laser shots are tested against its local copies of the other ships (as last received). A hit is written into the shooter's next packet as a hit report: "slot n was hit", with a flag for powered shots. The shooter scores 50 points per hit, at once; there is no extra reward for a kill.
  2. The victim's machine applies it when the packet arrives, at the end of its frame: −1 shield (−2 if powered), flash, and any stored cloak time is lost ("Cloak Destroyed!"), even if the cloak was switched off. At 0 shields the victim records the shooter as its killer.
  3. The shot copies you see from other players are only pictures; they never hit you (chapter 5).
  4. Ship-to-ship collisions are judged by each machine on its own; a collision kill names the other player as killer but gives nobody points.
  5. A cloaked ship is invisible in the others' views but still on their radars, can still be hit, and cannot fire.
  6. A packet carries one hit report per victim, so two of your shots hitting the same player in the same frame count once.
Quirk with consequences

The victim's machine reads the last packet received from each player every frame, whether or not a new one arrived. If a shooter's packets stop right after a hit (it crashed or its network dropped), that one hit is applied again in every frame: in a test, one hit took 20 shields in about 20 frames and the death countdown restarted every frame for as long as the shooter stayed silent (100 seconds in the test; runtime #24 in docs/runtime-baseline.md). Hit reports also still land on a player who is already dead.

For a rebuild

Keep the box tests with their sizes and orientations; they are the feel of aiming in NetWars (a laser that needs to be on target sideways but forgives a lot along the flight, alien shots that are hard to dodge sideways but sometimes pass through). If you want to remove the tunnelling and the point-blank blind spots (yours and the aliens'), test the shot's whole path segment for the frame instead of its end point; that is a deliberate change of feel, so make it a choice. Keep the frame order (your shots, then the aliens, then their shots), which decides who sees whose old position.

For multiplayer keep "the shooter decides", but send each hit report once with an id and have the victim acknowledge it, instead of re-reading the last packet: that removes the repeated-hit bug (chapter 8 and 13).

Exact rules: the box tests

All box tests work on whole units: the difference between target and shot is taken per axis in whole world units, rounded down, first checked against the rough cube, then dotted with the shot's axes (rounded down, chapter 3) and compared with the limits. Every limit is inclusive: "within ±512" means −512 ≤ value ≤ 512 (513 misses). Results can therefore differ from an exact floating-point test by a unit or so at the faces of the box.