Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add MathUtils.damp() for framerate independent lerping #21102

Merged
merged 2 commits into from
Jan 25, 2021

Conversation

marcofugaro
Copy link
Contributor

Related issue: -

Description

Another useful function is the damp function, which lets you interpolate in a spring-like manner, while being framerate independent.

The implementation comes from this article: Frame rate independent damping using lerp, where basically the author finds a better way of doing lerp(x, y, value * dt).

Unity also has this function nowadays, it's called SmoothDamp, however its implementation is a bit more complex.

@mrdoob mrdoob added this to the r125 milestone Jan 25, 2021
@mrdoob mrdoob merged commit cf47091 into mrdoob:dev Jan 25, 2021
@mrdoob
Copy link
Owner

mrdoob commented Jan 25, 2021

Thanks!

@makc
Copy link
Contributor

makc commented Jan 27, 2021

@marcofugaro it is somewhat weird in that in order to supply proper value of lambda users will have to be aware of damp() implementation. and if they are, why not just pass the expression to lerp themselves?

@marcofugaro
Copy link
Contributor Author

@makc

I think it's just necessary to read the documentation for the user, it says:

lambda - A higher lambda value will make the movement more sudden, and a lower value will make the movement more gradual.

@makc
Copy link
Contributor

makc commented Jan 28, 2021

I mean if I had, say, 40 fps and lerp(x, y, 0.1), to get similar results when switching to damp(...) I need to solve 0.1 = 1 - exp(-lambda * 25) - and docs just say, Idk try some values?

@makc
Copy link
Contributor

makc commented Jan 28, 2021

(p s on related note, docs say dt must be in seconds when in fact there is nothing that stops you from using other units like ms)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants