Last active
May 19, 2025 19:57
-
-
Save brihernandez/f3d709e6a0bea24a4c413f51e2e75a44 to your computer and use it in GitHub Desktop.
Framerate independent damping, Godot Edition
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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