The Godot Barn
Sign in
Sign in
Home
News & updates
Explore
Articles
Snippets
Shaders
Themes
Submit content
Sign in to submit content
Give or get help
Tutorials
Questions
Conversations
Coming soon!
Smoothing with expDecay instead of lerp()
4
Description
"based on this talk by freya:\r\nhttps:\/\/www.youtube.com\/watch?v=LSNQuFEDOyQ\r\n\r\n```gdscript\r\nclass_name Math\r\n\r\nstatic func expDecay(a:float, b:float, d:float, dt:float) -> float:\r\n return b+(a-b)*exp(-d*dt)\r\n\r\nstatic func expDecayVec2(a:Vector2, b:Vector2, d:float, dt:float) -> Vector2:\r\n return Vector2(\r\n expDecay(a.x, b.x, d, dt),\r\n expDecay(a.y, b.y, d, dt))\r\n\r\nstatic func expDecayVec3(a:Vector3, b:Vector3, d:float, dt:float) -> Vector3:\r\n return Vector3(\r\n expDecay(a.x, b.x, d, dt),\r\n expDecay(a.y, b.y, d, dt),\r\n expDecay(a.z, b.z, d, dt))\r\n```\r\n\r\nbasically, instead of `lerp()` i use this class script and call it wherever i need it instead.\r\n\r\nan example of it in action:\r\n\r\n```gdscript\r\nif crouched and is_on_floor():\r\n current_speed = Math.expDecay(current_speed,crouching_speed,decay,delta*smoothing_speed)\r\n walking = false\r\n sprinting = false\r\n```\r\n\r\nor\r\n\r\n```gdscript\r\nsway_mouse_input = Math.expDecayVec2(sway_mouse_input,Vector2.ZERO, decay, delta)\r\n```\r\n"
Comments
Log in to post a comment
Licensed under the Unlicense license
See the full license details
Submitted by
darkcanopy
Table of contents
Compatibility
Works in Godot
4.x
GDScript
Tags
No tags applied
Share this article
Share on Bluesky
Share on X / Twitter
or share this direct link:
https://thegodotbarn.com/contributions/article/13/smoothing-with-expdecay-instead-of-lerp
Please wait ...
Okay
Okay
No
Yes
Okay