Damped spring interpolation for scalar values.
Smoothly interpolates a value toward a target using spring physics. Useful for camera smoothing, UI animations, or any single-value spring behavior.
Current value
Target value to reach
Velocity object (modified in place)
Spring stiffness (higher = faster)
Damping factor (higher = less oscillation)
Time step in seconds
New interpolated value
// Smooth camera zoomconst velocity = { value: 0 };let currentZoom = 5;const targetZoom = 10;// In update loopcurrentZoom = dampedSpring( currentZoom, targetZoom, velocity, 10, // stiffness 5, // damping deltaTime);camera.position.z = currentZoom; Copy
// Smooth camera zoomconst velocity = { value: 0 };let currentZoom = 5;const targetZoom = 10;// In update loopcurrentZoom = dampedSpring( currentZoom, targetZoom, velocity, 10, // stiffness 5, // damping deltaTime);camera.position.z = currentZoom;
Damped spring interpolation for scalar values.
Smoothly interpolates a value toward a target using spring physics. Useful for camera smoothing, UI animations, or any single-value spring behavior.