summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRĂ©mi Verschelde <rverschelde@gmail.com>2020-04-13 09:17:04 +0200
committerGitHub <noreply@github.com>2020-04-13 09:17:04 +0200
commit6366332949a4e9cbf327b9b19f91cc879737bdeb (patch)
treef5c708781f7aa0624a22933cb611cee90b16d219
parent06748a2b5f3190c036dabd2560b39bde7676706d (diff)
parent2edb59ec8896d321f12b8fa6904bf13178be8bf8 (diff)
Merge pull request #37311 from MickeMakaron/handle-huge-path2d-offset-values
Handle huge path2d offset values
-rw-r--r--scene/2d/path_2d.cpp12
-rw-r--r--scene/3d/path_3d.cpp12
2 files changed, 10 insertions, 14 deletions
diff --git a/scene/2d/path_2d.cpp b/scene/2d/path_2d.cpp
index d55b21bc24..ed8481db4a 100644
--- a/scene/2d/path_2d.cpp
+++ b/scene/2d/path_2d.cpp
@@ -321,16 +321,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_3d.cpp b/scene/3d/path_3d.cpp
index f06135f53d..4a425d1e0e 100644
--- a/scene/3d/path_3d.cpp
+++ b/scene/3d/path_3d.cpp
@@ -316,16 +316,14 @@ void PathFollow3D::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);
}