Expand description
Small, renderer-independent tools for responsive arcade motion and impacts.
approach_vec2 and approach_vec3 limit the magnitude of change per
second: on velocities this bounds acceleration; on positions it bounds speed.
damp_vec2 and damp_vec3 instead decay the remaining error exponentially.
All four are allocation-free, accept caller-supplied time and retain no state.
Gameplay callers should supply their fixed simulation timestep.
With a constant target and rate, splitting time gives the same mathematical
result, subject to floating-point rounding on each call. Bounds likewise have
f32 rounding tolerance: very small changes can round away, and subnormal
components have coarse relative precision. Platform square root/exponential
operations do not establish cross-platform bitwise determinism.
Enums§
- Motion
Error - Invalid input to a checked approach or damping helper.
Functions§
- approach_
vec2 - Approach a 2D target by at most
max_rate * dtin Euclidean distance. - approach_
vec3 - Approach a 3D target by at most
max_rate * dtin Euclidean distance. - damp_
vec2 - Exponentially approach a 2D target without overshoot.
- damp_
vec3 - Exponentially approach a 3D target without overshoot.
- impact_
velocity - Change only an incoming velocity’s normal component and retain a chosen amount of tangential speed. Glancing contacts can slide without stopping. Invalid parameters/zero normals return None; separating velocities are intact.
- radial_
velocity - Bounded radial velocity change, with a smooth falloff to zero at the radius. Apply mass * result as an impulse to give light/heavy props equal launch speed.
- response
- Exponential approach weight, independent of render cadence. Invalid or nonpositive intervals/rates do no work; callers still own their fixed clock.