Ballistics modes: raycast vs projectile (travel time + bullet drop) #49

Open
opened 2026-11-15 15:16:38 +00:00 by muse-lantern · 0 comments
Member

The plan

Status: BACKBURNERED — filed 2026-11-15 at Zach's direction ("we can
backburner the idea for later"). No build authorized. When this is picked
up, breaking changes to the weapon/ballistics data shape are permitted;
none are to be made now.

The idea: weapons get a ballistics mode. Today every shot is a hitscan
raycast (Firearm._cast_shot, firearm.gd:389) with a beam tracer. The new
mode fires a simulated projectile with travel time and bullet drop,
rendered as a glowing bullet in flight.

The property

A mode key on the weapon struct, in the weapon's data table in
b_properties (alongside damage, rpm, spread_deg, range,
projectiles):

  • data.ballistics: "raycast" | "projectile", default "raycast".

The name is load-bearing: projectiles already exists and means pellet
count per shot (a shotgun fires N pellets), so the mode key must NOT be
called projectile. ballistics is the name.

The two modes

  • Raycast (default, today's behavior, unchanged): fire_once() calls
    _cast_shot per pellet — instant intersect_ray (range default 60 m),
    damage with falloff, WorldFx.tracer draws the beam from the muzzle to
    the hit point. Existing weapons keep this with no data changes.
  • Projectile: on fire_once, instead of _cast_shot, spawn a
    projectile entity per pellet: a small glowing bullet leaving the muzzle
    at muzzle velocity, gravity applied per physics frame, hit detection as
    a short swept raycast each step (same SHOT_MASK and exclusions as the
    raycast, so fast rounds don't tunnel). On hit it runs the SAME damage
    path as the raycast (falloff, damage_mult, Health.apply_damage,
    WorldFx.impact) so the two modes can't drift apart. On no hit inside
    its range it despawns. Shotguns just work: each pellet in the
    projectiles count becomes its own projectile.

The numbers

  • Velocity: the gun's velocity is an input. Muzzle velocity is a
    per-weapon value in the weapon data (the gun's velocity is part of the
    calculation). Whether the bullet also contributes per caliber
    (per-caliber base velocity, modified by the gun — the tier-model shape)
    is open; see Open questions.
  • Gravity is a world constant, not per-weapon (value TBD).
  • Scale (for feel): a 9mm at ~360 m/s crosses 60 m in ~0.17 s and
    drops ~14 cm — visible but small; slower subsonic rounds drop a lot
    more, which is where the bullet's subsonic tag ties in naturally.
  • No home today: the bullet's b_properties.ammo table is currently
    EMPTY (a round is just a model, tags, value, weight). Velocity data —
    wherever it lands — is new data to author.

The visuals

  • Raycast mode: the beam tracer (current WorldFx.tracer).
  • Projectile mode: a glowing bullet in flight (new WorldFx effect).
    Whether it reuses the bullet GLB or a cheap emissive mesh is open —
    the GLB is 2.25 MB and a small emissive shape reads better at speed.

What it touches (when built)

  • firearm.gd: branch in fire_once on the mode; a new projectile
    node/script with its own _physics_process (velocity, gravity, swept
    hit test, despawn).
  • WorldFx: the glowing-bullet visual (beam stays raycast-only).
  • Weapon JSONs: the ballistics key (default raycast, so existing
    weapons need no edits); velocity data wherever it lands.
  • Editor schema (item_schema.gd carries the defaults for the weapon
    data keys): the new key needs a schema entry to be authorable in the
    editor.
  • A projectile test (spawn, step, assert position/velocity/drop and a
    hit).
  • Docs: ballistics section in the modding docs.

Build order (when picked up)

  1. Mode key + schema default + raycast default (no behavior change).
  2. Projectile node + swept hit test + shared damage path.
  3. Glowing-bullet visual.
  4. Velocity data (per the decision below) + gravity constant.
  5. Projectile test + docs.

What done looks like

A weapon with ballistics: "projectile" fires a visible glowing bullet
that takes measurable time to arrive and drops over distance; a weapon
with "raycast" (or no key) behaves exactly as today. Both modes apply
damage through the same code. Tests cover a projectile's flight
(position, velocity, drop) and a hit.

Decisions already made

  • Backburnered (Zach, 2026-11-15): file it, build it later.
  • Velocity: the gun's velocity is an input to the projectile
    (per-weapon muzzle velocity in the weapon data).
  • Breaking changes: permitted when this is built, later — not now.
  • Mode key: data.ballistics, "raycast" default. (Not projectile
    — that name collides with the pellet-count key.)

Open questions

  • Velocity home, fully: gun-only, or per-caliber bullet base modified by
    the gun? (The tier model says the projectile gets stats from the bullet,
    modified by the gun — but the gun's velocity is the confirmed input.)
  • Gravity value: real 9.8 m/s² or game-tuned?
  • Glowing-bullet visual: reuse the bullet GLB or a cheap emissive mesh?
    Glow for every round, or only tracer-tagged rounds?
  • Max range / lifetime: what happens at max range — despawn, or drop to
    the ground as a physical round?
  • Hit exclusions: same as the raycast (shooter excluded, SHOT_MASK), or
    does the projectile also hit the shooter/friendlies?
  • Scope/timing: which branch/PR picks this up, and does it ride with
    anything else?
## The plan Status: BACKBURNERED — filed 2026-11-15 at Zach's direction ("we can backburner the idea for later"). No build authorized. When this is picked up, breaking changes to the weapon/ballistics data shape are permitted; none are to be made now. The idea: weapons get a ballistics mode. Today every shot is a hitscan raycast (`Firearm._cast_shot`, firearm.gd:389) with a beam tracer. The new mode fires a simulated projectile with travel time and bullet drop, rendered as a glowing bullet in flight. ### The property A mode key on the weapon struct, in the weapon's `data` table in `b_properties` (alongside `damage`, `rpm`, `spread_deg`, `range`, `projectiles`): - `data.ballistics`: `"raycast"` | `"projectile"`, default `"raycast"`. The name is load-bearing: `projectiles` already exists and means pellet count per shot (a shotgun fires N pellets), so the mode key must NOT be called `projectile`. `ballistics` is the name. ### The two modes - **Raycast (default, today's behavior, unchanged):** `fire_once()` calls `_cast_shot` per pellet — instant `intersect_ray` (range default 60 m), damage with falloff, `WorldFx.tracer` draws the beam from the muzzle to the hit point. Existing weapons keep this with no data changes. - **Projectile:** on `fire_once`, instead of `_cast_shot`, spawn a projectile entity per pellet: a small glowing bullet leaving the muzzle at muzzle velocity, gravity applied per physics frame, hit detection as a short swept raycast each step (same `SHOT_MASK` and exclusions as the raycast, so fast rounds don't tunnel). On hit it runs the SAME damage path as the raycast (falloff, `damage_mult`, `Health.apply_damage`, `WorldFx.impact`) so the two modes can't drift apart. On no hit inside its range it despawns. Shotguns just work: each pellet in the `projectiles` count becomes its own projectile. ### The numbers - **Velocity: the gun's velocity is an input.** Muzzle velocity is a per-weapon value in the weapon data (the gun's velocity is part of the calculation). Whether the bullet also contributes per caliber (per-caliber base velocity, modified by the gun — the tier-model shape) is open; see Open questions. - **Gravity** is a world constant, not per-weapon (value TBD). - **Scale (for feel):** a 9mm at ~360 m/s crosses 60 m in ~0.17 s and drops ~14 cm — visible but small; slower subsonic rounds drop a lot more, which is where the bullet's subsonic tag ties in naturally. - **No home today:** the bullet's `b_properties.ammo` table is currently EMPTY (a round is just a model, tags, value, weight). Velocity data — wherever it lands — is new data to author. ### The visuals - Raycast mode: the beam tracer (current `WorldFx.tracer`). - Projectile mode: a glowing bullet in flight (new `WorldFx` effect). Whether it reuses the bullet GLB or a cheap emissive mesh is open — the GLB is 2.25 MB and a small emissive shape reads better at speed. ### What it touches (when built) - `firearm.gd`: branch in `fire_once` on the mode; a new projectile node/script with its own `_physics_process` (velocity, gravity, swept hit test, despawn). - `WorldFx`: the glowing-bullet visual (beam stays raycast-only). - Weapon JSONs: the `ballistics` key (default raycast, so existing weapons need no edits); velocity data wherever it lands. - Editor schema (`item_schema.gd` carries the defaults for the weapon data keys): the new key needs a schema entry to be authorable in the editor. - A projectile test (spawn, step, assert position/velocity/drop and a hit). - Docs: ballistics section in the modding docs. ### Build order (when picked up) 1. Mode key + schema default + raycast default (no behavior change). 2. Projectile node + swept hit test + shared damage path. 3. Glowing-bullet visual. 4. Velocity data (per the decision below) + gravity constant. 5. Projectile test + docs. ### What done looks like A weapon with `ballistics: "projectile"` fires a visible glowing bullet that takes measurable time to arrive and drops over distance; a weapon with `"raycast"` (or no key) behaves exactly as today. Both modes apply damage through the same code. Tests cover a projectile's flight (position, velocity, drop) and a hit. ## Decisions already made - **Backburnered** (Zach, 2026-11-15): file it, build it later. - **Velocity:** the gun's velocity is an input to the projectile (per-weapon muzzle velocity in the weapon data). - **Breaking changes:** permitted when this is built, later — not now. - **Mode key:** `data.ballistics`, `"raycast"` default. (Not `projectile` — that name collides with the pellet-count key.) ## Open questions - Velocity home, fully: gun-only, or per-caliber bullet base modified by the gun? (The tier model says the projectile gets stats from the bullet, modified by the gun — but the gun's velocity is the confirmed input.) - Gravity value: real 9.8 m/s² or game-tuned? - Glowing-bullet visual: reuse the bullet GLB or a cheap emissive mesh? Glow for every round, or only tracer-tagged rounds? - Max range / lifetime: what happens at max range — despawn, or drop to the ground as a physical round? - Hit exclusions: same as the raycast (shooter excluded, SHOT_MASK), or does the projectile also hit the shooter/friendlies? - Scope/timing: which branch/PR picks this up, and does it ride with anything else?
Commenting is not possible because the repository is archived.
No labels
No milestone
No project
No assignees
1 participant
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
dead-air/engine-legacy#49
No description provided.