-
-
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
Fix smooth follow example in interpolation #6134
Conversation
Old method is not really frame-independent. Formula with explanation found from https://www.gamedeveloper.com/programming/improved-lerp-smoothing-
Notice: I tested the code only in 3.x build, then changed |
Adding link since OP hasn't https://docs.godotengine.org/en/latest/tutorials/math/interpolation.html The version currently at the docs does interpolate evenly but it jitters. Your version is better as its smooth without jitter. I don't like that the code is slightly more complicated (newbies will use it but won't understand it, compared to current version), but the results are worth it imo. |
Who can make a call on wether if we merge this or not? |
|
||
$Sprite2D.position = $Sprite2D.position.lerp(mouse_pos, delta * FOLLOW_SPEED) |
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 suggest keeping the current version, but adding a comment right after :
# An alternative version with even smoother results and a little more math :
# $Sprite2D.position = $Sprite2D.position.lerp(mouse_pos, 1 - exp(-FOLLOW_SPEED * delta))
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 don't know. Kind of kills the idea of fixing the incorrect method in the first place.
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.
But the original method is not really wrong in itself. It just produces less smooth results, which might not be a problem in the context of a beginners tutorial.
|
||
sprite.Position = sprite.Position.Lerp(mousePos, delta * FollowSpeed); |
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.
Same as above
} | ||
|
||
Here is how it looks: | ||
|
||
.. image:: img/interpolation_follow.gif | ||
|
||
This useful for smoothing camera movement, allies following you (ensuring they stay within a certain range), and many other common game patterns. | ||
This is useful for smoothing camera movement, allies following you (ensuring they stay within a certain range), and many other common game patterns. Notice that making movement framerate-independent is more involved than just multiplying weight by delta 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.
The final notice not only doesn't bring much information, but may add confusion. I'd rather not add it.
I feel this trick's worth mentioning indeed, but it's true it may be a little bit too much involved for beginners. I suggest keeping the more pedagogical current version, but mentioning the improved one as a comment for advanced users. |
Old method is not really frame-independent. Formula with explanation found from here.