Skip to content

Instantly share code, notes, and snippets.

@brihernandez
Last active May 19, 2025 19:57
Show Gist options
  • Save brihernandez/f3d709e6a0bea24a4c413f51e2e75a44 to your computer and use it in GitHub Desktop.
Save brihernandez/f3d709e6a0bea24a4c413f51e2e75a44 to your computer and use it in GitHub Desktop.
Framerate independent damping, Godot Edition
class_name Maths
# For more information on why this is so important, see the link below:
# See https://www.rorydriscoll.com/2016/03/07/frame-rate-independent-damping-using-lerp/
static func smooth_to(from: float, to: float, speed: float, dt: float) -> float:
return lerpf(from, to, 1 - exp(-speed * dt));
static func smooth_to_vec(from: Vector3, to: Vector3, speed: float, dt: float) -> Vector3:
return from.lerp(to, 1 - exp(-speed * dt))
static func smooth_to_quat(from: Quaternion, to: Quaternion, speed: float, dt: float) -> Quaternion:
return from.slerp(to, 1 - exp(-speed * dt))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment