standard lerp is frame rate dependent - is ours? #5290
Replies: 8 comments 10 replies
-
@BaddRadish I guess yes, it's rate dependent. If i got a point of question right.
|
Beta Was this translation helpful? Give feedback.
-
Not if you use |
Beta Was this translation helpful? Give feedback.
-
It might hold some value to provide alternative version which can be used frame-independent way. It's not about 'fixing' something that's broken, since linear interpolation is, by definition what it is. |
Beta Was this translation helpful? Give feedback.
-
ah yes i see now, good point - it should be safe AND effective to use the lerp we have now as long as you use the same starting position each time, instead of updating per frame. still, there /might/ be situations where thats not desired? maybe? like if the target keeps moving every frame. this is still doable probably, since the process rate would likely stay the same. you would lerp correctly in physics process, then use the end position as the new start in process. something like that. so this might still make a decent additional feature. side benefit: having the extra function around would remind people to not abuse the lerp we have now lol. but honestly who wants the bloat. |
Beta Was this translation helpful? Give feedback.
-
Being picky here: lerp means linear interpolation. And it has nothing to do with frames. Now, you might want to lerp over time. If you have a fixed target and you compute the time correctly there is no problem. As alternative you can use tweens, and I would encourage you to. But people use lerp a different way: they use it to approach a moving target. That is a cheap way to implement a different behavior: damping. But damping implemented with lerp the naive way is frame rate dependent. You can solve this by using exponential, which the linked article mentions. Sadly the linked article does not mention the word "damping". If you think of it in terms of damping, you will get a different idea: the velocity of a spring depends on the distance, not the time. Ok, you can think of it as "rubber banding" and get to the same idea. Thus, you can define a maximum speed, a distance at which it should reach that speed, and an easing function from zero to there. And this way you keep control over the behavior (by changing the easing function. Yes, you can still use a lerp). |
Beta Was this translation helpful? Give feedback.
-
# this is frame rate dependent
position = lerp(position, target_position, weight * delta)
# this is not frame rate dependent, but more or less the same as `move_toward()`
current_weight += delta * speed
position = lerp(start_position, target_position, current_weight) I think the overall intension of the "frame rate dependent" version is not to do linear interpolation, calling So it's not Edit: ah, just saw @theraot 's comment after posting this one 😂 we're saying basically the same thing. |
Beta Was this translation helpful? Give feedback.
-
You wouldn't lerp by a constant if you wanted frame rate independence. Here's what I always do:
You won't need a different function to lerp consistently over time if you do it this way. This also makes it easier to "tune" your values because you set an exact duration. |
Beta Was this translation helpful? Give feedback.
-
As mentioned already, the I'm going to close this discussion, as the discussion seems to have run its course, and the tangible docs improvement suggested here has been made. |
Beta Was this translation helpful? Give feedback.
-
so i found this article that points out the fact that standard lerp is frame rate dependent.
https://www.gamedeveloper.com/programming/improved-lerp-smoothing-
a significant portion of lerp use cases is for changes over time. maybe even the majority.
higher frame rates means more calls to lerp.
yes its called with less delta, but that only fixes move_toward, not lerp.
does our lerp have this issue?
if so, the problem might also be present in slerp as well.
the article offers a solution: exponential lerp.
it might be seriously worth considering fixing this or at least adding this as an alternative!
we should potentially keep the original lerp around for one time lerping.
it would probably be trivial to scale the new lerp to the default frame rate.
this way, most users can just swap it out without requiring additional changes.
or is this solution already implemented in godot?
thanks!
Beta Was this translation helpful? Give feedback.
All reactions