Back to Poly Dogfight
SOURCE / PINNED RELEASE

Made of little things.

Poly Dogfight

Release
b8511ee374e3…
Author-recorded commit
5579434b9d8b…
License
LICENSE
Author’s source reference
nostr://npub1ye5ptcxfyyxl5vjvdjar2ua3f0hynkjzpx552mu5snj3qmx5pzjscpknpr/wss%3A%2F%2Fgit.napplet.soy%2F/n-44f63e5422b

Archive hash verified: bcadd2430d8ea2bc…. The source-to-build association is the author’s claim; it has not been independently rebuilt.

src/sim/hit-boxes.ts
import { Vector3 } from 'three';
import type { DamagePart } from './flight.ts';

export type Box = { part: DamagePart | 'armor'; min: [number, number, number]; max: [number, number, number] };

/**
 * Hit boxes in body axes (nose -Z, up +Y, right wing +X), slightly generous
 * for arcade aiming. The front fuselage (engine and cockpit) is armoured: it
 * stops rounds without damage, while the rear fuselage counts as tail.
 */
export const HIT_BOXES: readonly Box[] = [
  { part: 'left', min: [-3.4, -0.55, -1.3], max: [-0.45, 1.3, 0.2] },
  { part: 'right', min: [0.45, -0.55, -1.3], max: [3.4, 1.3, 0.2] },
  { part: 'tail', min: [-1.2, -0.1, 1.9], max: [1.2, 1.15, 3.05] },
  { part: 'tail', min: [-0.5, -0.35, 0.6], max: [0.5, 0.65, 1.9] },
  { part: 'armor', min: [-0.55, -0.5, -2.25], max: [0.55, 0.8, 0.6] },
];

/**
 * Where a segment from `a` to `b` first enters an axis-aligned box, as a
 * fraction 0..1 of its length, or null if it misses.
 */
export function segmentBoxEntry(a: Vector3, b: Vector3, min: readonly number[], max: readonly number[]): number | null {
  let t0 = 0;
  let t1 = 1;
  const start = [a.x, a.y, a.z];
  const delta = [b.x - a.x, b.y - a.y, b.z - a.z];
  for (let axis = 0; axis < 3; axis++) {
    const s = start[axis]!;
    const d = delta[axis]!;
    if (Math.abs(d) < 1e-9) {
      if (s < min[axis]! || s > max[axis]!) return null;
      continue;
    }
    let near = (min[axis]! - s) / d;
    let far = (max[axis]! - s) / d;
    if (near > far) [near, far] = [far, near];
    t0 = Math.max(t0, near);
    t1 = Math.min(t1, far);
    if (t0 > t1) return null;
  }
  return t0;
}