Skip to main content

smooth_damp

Function smooth_damp 

Source
pub fn smooth_damp(
    current: f32,
    target: f32,
    velocity: f32,
    smooth_time: f32,
    dt: f32,
) -> (f32, f32)
Expand description

Critically damped spring towards target (like a camera “smooth damp”): returns the new value and the new velocity. Keep the velocity between calls. smooth_time is roughly the seconds to arrive.

use kvas_engine::math::smooth_damp;
let (mut x, mut v) = (0.0, 0.0);
for _ in 0..120 { (x, v) = smooth_damp(x, 10.0, v, 0.3, 1.0 / 60.0); }
assert!((x - 10.0).abs() < 0.05);