Module motion

Source
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§

MotionError
Invalid input to a checked approach or damping helper.

Functions§

approach_vec2
Approach a 2D target by at most max_rate * dt in Euclidean distance.
approach_vec3
Approach a 3D target by at most max_rate * dt in 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.