The Godot Barn
Sign in
Sign in
Home
News & updates
Explore
Tutorials
Articles
Snippets
Shaders
Submit content
Sign in to submit content
Give or get help
Questions
Conversations
Coming soon!
Smoothing with expDecay instead of lerp()
3
Description
"based on this talk by freya:\nhttps:\/\/www.youtube.com\/watch?v=LSNQuFEDOyQ\n\n```gdscript\nclass_name Math\n\nstatic func expDecay(a:float, b:float, d:float, dt:float) -> float:\n return b+(a-b)*exp(-d*dt)\n\nstatic func expDecayVec2(a:Vector2, b:Vector2, d:float, dt:float) -> Vector2:\n return Vector2(\n expDecay(a.x, b.x, d, dt),\n expDecay(a.y, b.y, d, dt))\n\nstatic func expDecayVec3(a:Vector3, b:Vector3, d:float, dt:float) -> Vector3:\n return Vector3(\n expDecay(a.x, b.x, d, dt),\n expDecay(a.y, b.y, d, dt),\n expDecay(a.z, b.z, d, dt))\n```\n\nbasically, instead of `lerp()` i use this class script and call it wherever i need it instead.\n\nan example of it in action:\n\n```gdscript\nif crouched and is_on_floor():\n current_speed = Math.expDecay(current_speed,crouching_speed,decay,delta*smoothing_speed)\n walking = false\n sprinting = false\n```\n\nor\n\n```gdscript\nsway_mouse_input = Math.expDecayVec2(sway_mouse_input,Vector2.ZERO, decay, delta)\n```\n"
Comments
Log in to post a comment
Licensed under the CC-BY 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