game/combat/fight — the arithmetic the combat slice shares between its two
components (`Emberward` and `CombatCamera`).
Nothing here touches state. It is angles, distances, damping and a shake
accumulator: the parts both files need and neither should own.
local Fight = require("game.combat.fight")
local yaw = Fight.yawTo(from, to)
YAW CONVENTION, matching the engine's own rigs: `yaw` is measured about +Y
from world +Z, and the forward it names is `(sin yaw, 0, cos yaw)`. An
unrotated body faces +Z, so a yaw of 0 is a body facing the saint.
damp(current: number, goal: number, tau: number, dt: number) → number
Frame-rate independent approach toward a goal. `tau` is the time constant
in seconds: the value covers ~63% of the remaining distance in one.
| arg | type | description |
|---|
| current | number | |
| goal | number | |
| tau | number | |
| dt | number | |
xyz(p: any) → void
Read any position-ish value into three plain numbers.
horizDist(a: any, b: any) → number
Distance between two points on the ground plane.
| arg | type | description |
|---|
| a | any | |
| b | any | |
yawTo(a: any, b: any) → number
The yaw that points from `a` toward `b`, on the ground plane.
| arg | type | description |
|---|
| a | any | |
| b | any | |
angleDelta(from: number, to: number) → number
Signed shortest angle from `from` to `to`, in radians, in (-pi, pi].
| arg | type | description |
|---|
| from | number | |
| to | number | |
yawQuat(yaw: number) → void
A quaternion for a rotation about +Y, as the array the transform takes.
| arg | type | description |
|---|
| yaw | number | |
inArc(origin: any, yaw: number, target: any, arcDegrees: number, range: number) → boolean
Is `target` inside a cone of `arcDegrees` centred on `yaw`, within `range`?
An arc of 360 or more is every direction, and only the range is tested.
| arg | type | description |
|---|
| origin | any | |
| yaw | number | |
| target | any | |
| arcDegrees | number | |
| range | number | |
addShake(s: Shake, amplitude: number, duration: number) → void
Add an impact. `amplitude` is 0..1-ish; `duration` sets how fast it decays.
| arg | type | description |
|---|
| s | Shake | |
| amplitude | number | |
| duration | number | |
calmShake(s: Shake) → void
Drop every impact in flight at once. What a cut to a new shot wants: the
shake belongs to the blow that caused it, not to the frame after the cut.
sampleShake(s: Shake, dt: number, scale: number) → void
Advance the shake and read this frame's offset, in metres.
| arg | type | description |
|---|
| s | Shake | |
| dt | number | |
| scale | number | |