Handle huge offset values in Path2D and Path3D set_offset

This commit is contained in:
MickeMakaron 2020-04-13 07:42:47 +02:00
parent 06748a2b5f
commit 2edb59ec88
2 changed files with 10 additions and 14 deletions

View file

@ -321,16 +321,14 @@ void PathFollow2D::set_offset(float p_offset) {
offset = p_offset; offset = p_offset;
if (path) { 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(); float path_length = path->get_curve()->get_baked_length();
if (loop) { if (loop) {
while (offset > path_length) offset = Math::fposmod(offset, path_length);
offset -= path_length; if (!Math::is_zero_approx(p_offset) && Math::is_zero_approx(offset)) {
offset = path_length;
while (offset < 0) }
offset += path_length;
} else { } else {
offset = CLAMP(offset, 0, path_length); offset = CLAMP(offset, 0, path_length);
} }

View file

@ -316,16 +316,14 @@ void PathFollow3D::set_offset(float p_offset) {
offset = p_offset; offset = p_offset;
if (path) { 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(); float path_length = path->get_curve()->get_baked_length();
if (loop) { if (loop) {
while (offset > path_length) offset = Math::fposmod(offset, path_length);
offset -= path_length; if (!Math::is_zero_approx(p_offset) && Math::is_zero_approx(offset)) {
offset = path_length;
while (offset < 0) }
offset += path_length;
} else { } else {
offset = CLAMP(offset, 0, path_length); offset = CLAMP(offset, 0, path_length);
} }