Handle huge offset values in Path2D and Path3D set_offset
(cherry picked from commit 2edb59ec88
)
This commit is contained in:
parent
5d9108c9c6
commit
e3ca6d87ad
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue