-
-
Notifications
You must be signed in to change notification settings - Fork 21.4k
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
Fixed interpolation for discrete types #53548
Conversation
discrete interpolation now uses Math::round to closely match real types. fixed interpolation formula for discrete types other than int.
I believe this might have been superseded by some PRs by @TokageItLab, could you confirm? |
I refactored it, but the algorithm was still retained, so I don't think it is a replacement for this PR. At a quick look this change seems to make sense. But we need to test how ilerp is done elsewhere and whether this will cause problems (well, still I feel positive towards this change). |
cc @KoBeWi I think this relates to also tween. |
Tweens have a problem (which is not a bug) with interpolating sprite's frames (although it's the same with AnimationPlayer). When you interpolate from This short code showcases the issue: var tween = get_editor_interface().get_edited_scene_root().create_tween().set_process_mode(Tween.TWEEN_PROCESS_PHYSICS)
tween.tween_method(func(v): print(v), 0, 10, 1) The output is:
Notice how 10 appears once. I tested how this behaves with
The first frame appears less times and the last frame appears more times. While it's still not perfect, it improves the usability a bit I guess. |
Ah indeed. At least as far as we think about int, the current master's code may be more ideal for controlling frames in the timeline for AnimatedSprite, since the borders are clearer. But for simple interpolation of values, a transition like this PR would be preferable. Well, allowing them to be switched would be ideal, but seems a bit too expensive. It is not impossible to do such a transition only for Vector2i, but it does not seem like a good idea from a consistency standpoint... It might be better to leave them as they are for now. |
Superseded by #84815. |
This fixes the animation player interpolating discrete types like Vector2i.
int
: int is now interpolated usingMath::round()
instead of standard cast to int.This aligns better with real types. Also only (-.5,0.5) is mapped to 0 instead of (-1,1) so interpolation is more 'linear' around zero.
Other types have their formula corrected. They use the same rounding behavior as int for consistency.
Somewhat unrelated: Should
Variant::blend()
be dropped? I can not find any uses in the engine, but it is exposed to GdNative. It does less thanVariant::interpolate()
and contains more bugs.Edit: For testing be sure to interpolate values other than 0, otherwise the changes aren't visible.