Time in seconds at which a projectile fired now from shooterPosition at
projectileSpeed meets a target that is at targetPosition and moving at the
constant targetVelocity — the "lead" or interception time. NaN when no
interception exists (see the module note on the no-solution policy).
Writing R = targetPosition − shooterPosition, the projectile can be anywhere
on a sphere of radius projectileSpeed · t after t seconds, so an
interception is a t >= 0 with
|R + targetVelocity · t| = projectileSpeed · t
Squaring (safe for t >= 0, where both sides are non-negative, so no spurious
root is introduced) gives the quadratic
The smallest root >= 0 is returned: when a target faster than the
projectile crosses the shooter's reach there can be two future interceptions,
and the earlier one is the shot a player expects. A degenerate leading
coefficient (target speed exactly equal to projectile speed) is handled as the
linear equation it is: interception then exists only while the target is
closing (R · targetVelocity < 0).
NaN therefore covers exactly the cases with no answer — a target receding
faster than the projectile, a projectile too slow to catch up, a zero
projectileSpeed against a target that is not already at the shooter.
0 is returned when the target is already at the shooter.
The direction to fire is (interceptPoint − shooterPosition) normalized; the
speed is projectileSpeed by construction. Gravity is not modelled — this
is the straight-line lead of §111's "trajectory prediction"; a ballistic
launch solve (solving for the angle under gravity) is a different problem and
is not part of this packet.
Time in seconds at which a projectile fired now from
shooterPositionatprojectileSpeedmeets a target that is attargetPositionand moving at the constanttargetVelocity— the "lead" or interception time.NaNwhen no interception exists (see the module note on the no-solution policy).Writing
R = targetPosition − shooterPosition, the projectile can be anywhere on a sphere of radiusprojectileSpeed · taftertseconds, so an interception is at >= 0withSquaring (safe for
t >= 0, where both sides are non-negative, so no spurious root is introduced) gives the quadraticThe smallest root
>= 0is returned: when a target faster than the projectile crosses the shooter's reach there can be two future interceptions, and the earlier one is the shot a player expects. A degenerate leading coefficient (target speed exactly equal to projectile speed) is handled as the linear equation it is: interception then exists only while the target is closing (R · targetVelocity < 0).NaNtherefore covers exactly the cases with no answer — a target receding faster than the projectile, a projectile too slow to catch up, a zeroprojectileSpeedagainst a target that is not already at the shooter.0is returned when the target is already at the shooter.The direction to fire is
(interceptPoint − shooterPosition)normalized; the speed isprojectileSpeedby construction. Gravity is not modelled — this is the straight-line lead of §111's "trajectory prediction"; a ballistic launch solve (solving for the angle under gravity) is a different problem and is not part of this packet.