Log inGet started
World

Painted Metropolis

Branchmain
Commit1e1d3a3d4d

README.md

ballistics

Paint in the air: projectiles that fly real arcs and hit what is in the way.

A projectile is a point with a velocity under gravity. Each step it moves along its arc in sub-steps no longer
than cfg.ballistics.step and the segment it covered is tested against the world through a query the host
injects, so a pellet cannot tunnel through a wall and the kit never touches a physics engine itself.

  local Ballistics = require("~.modules.ballistics")
  local air = Ballistics.new(cfg.ballistics, query)
  -- query.raycast(origin, dir, distance, exclude) -> hit | nil
  --     origin, dir = { x, y, z } (dir is unit); exclude = the firer's id or nil
  --     hit = { x, y, z, nx, ny, nz, distance, kind = "wall", target = id?, part = name?, lx?, ly?, lz? }
  --     kind names what was hit (a surface kind or a cover kind); target is the thing's id when it is a thing
  --     and not the static world; part and the local point (lx, ly, lz) are optional detail for things
  -- query.overlap(centre, radius) -> { { target, kind, part?, x, y, z } }    (only needed for splash and cones)
  for _, shot in fired.shots do air:spawn(shot) end           -- shots as modules/arms makes them
  local events = air:step(dt)
  -- { type = "impact", shot, hit }      the shot ended on something (hit as the query returned it, plus speed)
  -- { type = "spent", shot, x, y, z }   it flew its range and fell away
  air:count()   air:each(function(shot) end)   air:clear()    -- what is flying now (for drawing it)

Without a flight:
  Ballistics.cone(query, cone) -> { hit, ... }       everything a cone pulse reaches with a clear line, nearest first
  Ballistics.splash(query, shot, hit) -> { hit, ... } things within shot.splash of an impact (falloff in hit.share)
  Ballistics.arc(shot, seconds, n, query?) -> { { x, y, z } }, hit?     points along a shot's path, for an aim line
  Ballistics.lobVelocity(from, to, speed, gravity, high?) -> vx, vy, vz | nil   the launch that lands a lob on a point
  Ballistics.lead(from, target, targetVelocity, speed) -> { x, y, z }           where to aim at something moving

Everything is deterministic: the same shots and the same world give the same events in the same order.

The interface is documented in the header of init.luau; this file repeats it for the asset browser.