From f670ece88f9e62b881dfbd806c02faa992a2c876 Mon Sep 17 00:00:00 2001 From: "Silc Lizard (Tokage) Renew" <61938263+TokageItLab@users.noreply.github.com> Date: Wed, 12 Feb 2025 08:20:30 +0900 Subject: [PATCH] Fix interpolation on the end edge in non-loop animation --- scene/resources/animation.cpp | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/scene/resources/animation.cpp b/scene/resources/animation.cpp index 109dceb0956..46377cd028c 100644 --- a/scene/resources/animation.cpp +++ b/scene/resources/animation.cpp @@ -2562,11 +2562,13 @@ T Animation::_interpolate(const Vector> &p_keys, double p_time, Interpol if (is_start_edge) { idx = p_backward ? maxi : 0; } - next = CLAMP(idx + (p_backward ? -1 : 1), 0, maxi); + int len2 = MIN(len, p_keys.size() - 1); + next = CLAMP(idx + (p_backward ? -1 : 1), 0, len2); if (use_cubic) { - pre = CLAMP(idx + (p_backward ? 1 : -1), 0, maxi); - post = CLAMP(idx + (p_backward ? -2 : 2), 0, maxi); + pre = CLAMP(idx + (p_backward ? 1 : -1), 0, len2); + post = CLAMP(idx + (p_backward ? -2 : 2), 0, len2); } + is_end_edge = p_backward ? idx == 0 : idx >= len2; // TODO: The process needs to be commonized early on without overriding, but all other branches need to be refactored to prevent to collapse loop_wrap key acquisition. } else if (loop_mode == LOOP_LINEAR) { if (is_start_edge) { idx = p_backward ? 0 : maxi;