From e3ca6d87adacbd2701a1981f8117d0bcb1dff56e Mon Sep 17 00:00:00 2001 From: MickeMakaron Date: Mon, 13 Apr 2020 07:42:47 +0200 Subject: [PATCH] Handle huge offset values in Path2D and Path3D set_offset (cherry picked from commit 2edb59ec8896d321f12b8fa6904bf13178be8bf8) --- scene/2d/path_2d.cpp | 12 +++++------- scene/3d/path.cpp | 12 +++++------- 2 files changed, 10 insertions(+), 14 deletions(-) diff --git a/scene/2d/path_2d.cpp b/scene/2d/path_2d.cpp index ef7c343c1a8..e777ea2e7d7 100644 --- a/scene/2d/path_2d.cpp +++ b/scene/2d/path_2d.cpp @@ -322,16 +322,14 @@ void PathFollow2D::set_offset(float p_offset) { offset = p_offset; if (path) { - if (path->get_curve().is_valid() && path->get_curve()->get_baked_length()) { + if (path->get_curve().is_valid()) { float path_length = path->get_curve()->get_baked_length(); if (loop) { - while (offset > path_length) - offset -= path_length; - - while (offset < 0) - offset += path_length; - + offset = Math::fposmod(offset, path_length); + if (!Math::is_zero_approx(p_offset) && Math::is_zero_approx(offset)) { + offset = path_length; + } } else { offset = CLAMP(offset, 0, path_length); } diff --git a/scene/3d/path.cpp b/scene/3d/path.cpp index ac012de1abb..5fa0b4fa77c 100644 --- a/scene/3d/path.cpp +++ b/scene/3d/path.cpp @@ -317,16 +317,14 @@ void PathFollow::set_offset(float p_offset) { offset = p_offset; if (path) { - if (path->get_curve().is_valid() && path->get_curve()->get_baked_length()) { + if (path->get_curve().is_valid()) { float path_length = path->get_curve()->get_baked_length(); if (loop) { - while (offset > path_length) - offset -= path_length; - - while (offset < 0) - offset += path_length; - + offset = Math::fposmod(offset, path_length); + if (!Math::is_zero_approx(p_offset) && Math::is_zero_approx(offset)) { + offset = path_length; + } } else { offset = CLAMP(offset, 0, path_length); }