-
-
Notifications
You must be signed in to change notification settings - Fork 3.3k
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
Improve interpolation smoothing example #10197
Conversation
Interpolation can be used to smooth movement, rotation, etc. Here is an example of a circle following the mouse using smoothed motion: | ||
Interpolation can be used to smoothly follow a moving target value, such as a | ||
position or a rotation. Each frame, ``lerp()`` moves the current value towards | ||
the target value by a fixed percentage of the remaining difference between the values. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"Percentage" is technically incorrect here, since the value is in the range of [0,1]
rather than [0,100]
. "Portion" or maybe "fraction" is more technically correct, but have the wrong connotations - in English, "portion" can also mean a fixed amount rather than a value that depends on the total value.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this is fine as is, I agree with the reasoning.
I think there is something getting lost here by removing "Interpolation can be used to smooth movement, rotation, etc". Thats actually telling less experienced users what this whole thing is useful for, which is my biggest quibble with the current state of the page.
Starting the page with "Interpolation is a very basic operation in graphics programming. It's good to become familiar with it in order to expand your horizons as a graphics developer" and "interpolation can be described as A * (1 - t) + B * t" is likely to lose a lot of less mathematically minded users.
I'd actually like to see the above sentence somewhere near the intro, a short what is this actually useful for in my game.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd be happy to do a pass on the rest of the page too, but I think that's slightly out of scope of this PR which just aims to improve the section on using lerp() to follow a moving target (or "lerp smoothing").
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In that case I'm fine with this as is, too. That example is better for the beginning rather halfway down the page, anyway.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I made a change to the very first paragraph:
- bringing the removed sentence to the beginning of the page
- removing one of the banned words "basic"
- changing "graphics developer" to "game developer"
To be clear, the rest of this page still needs more work, but it's beyond the scope of this PR.
tutorials/math/interpolation.rst
Outdated
the ``weight`` parameter of ``lerp()`` represents a *percentage* of the remaining | ||
difference in values, not an *absolute amount to change*. In ``_physics_process()``, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If it's not clear from a single sentence, explaining why weight
being a percentage rather than an absolute amount matters feels beyond the scope of the docs. There are two good links to get a deeper explanation, if the reader wants them.
Of course, if the single sentence can be made more clear we should do that!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this is fine.
LGTM, keeps it simple while explaining the topic with enough depth. |
f5523ec
to
3ea9fa2
Compare
Improves explanation of interpolation ("lerp") smoothing. Adds a note about framerate-independent version, with off-site links to full explanations. Co-Authored-By: aXu-AP <[email protected]>
3ea9fa2
to
012f0b8
Compare
Thank you! |
Supersedes #6134.
Improves explanation of interpolation smoothing ("lerp smoothing").
Adds a note about framerate-independent version, with off-site links to full explanations.
I believe keeping the current, framerate-dependent version is good. It is simpler, and is required context appreciate the framerate-independent version. (I would also like to include the truly naive version with no
delta
:$Sprite2D.position = $Sprite2D.position.lerp(mouse_pos, FOLLOW_SPEED)
. But the explanation would be too long.)The explanation of the framerate-independent version belongs in a note. The simple version does actually work in most cases, because physics delta is consistent in normal gameplay, more so than process delta.
Unfortunately, while it's easy enough to explain why just multiplying by
delta
doesn't work, it's hard to concisely explain why the framerate-independent version works. So I also included links to the a short-ish article deriving the better formula, and to a good but very long video on the problem and how to derive the better formula.Both GDScript and C# examples have been tested and confirmed to work. I did not deeply test the formulas at varying framerates, though.
Note that the form used in this PR:
seems different than the form used in the article (after changing the names and
lerp()
function signature):It's equivalent if you flip the
target
andvalue
, and compensate with a1 - x
though:Note also that we use
exp()
in place ofexp2()
. This is still valid; only therate
value needs to change to compensate for the change in exponential base.