From e23f6a5bba79e995642610fd0e128b49414f5d9f Mon Sep 17 00:00:00 2001 From: Raul Santos Date: Wed, 28 Jul 2021 21:42:26 +0200 Subject: [PATCH] Fix forward calculation in PathFollow3D for the position at the end of the curve --- scene/3d/path_3d.cpp | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/scene/3d/path_3d.cpp b/scene/3d/path_3d.cpp index 6af2e7f8792..490cf5fe670 100644 --- a/scene/3d/path_3d.cpp +++ b/scene/3d/path_3d.cpp @@ -100,11 +100,18 @@ void PathFollow3D::_update_transform(bool p_update_xyz_rot) { } float bi = c->get_bake_interval(); float o_next = offset + bi; + float o_prev = offset - bi; if (loop) { o_next = Math::fposmod(o_next, bl); - } else if (rotation_mode == ROTATION_ORIENTED && o_next >= bl) { - o_next = bl; + o_prev = Math::fposmod(o_prev, bl); + } else if (rotation_mode == ROTATION_ORIENTED) { + if (o_next >= bl) { + o_next = bl; + } + if (o_prev <= 0) { + o_prev = 0; + } } Vector3 pos = c->interpolate_baked(offset, cubic); @@ -113,7 +120,12 @@ void PathFollow3D::_update_transform(bool p_update_xyz_rot) { // will be replaced by "Vector3(h_offset, v_offset, 0)" where it was formerly used if (rotation_mode == ROTATION_ORIENTED) { - Vector3 forward = c->interpolate_baked(o_next, cubic) - pos; + Vector3 forward = c->interpolate_baked(o_next, cubic); + + // Try with the previous position + if (forward.length_squared() < CMP_EPSILON2) { + forward = pos - c->interpolate_baked(o_prev, cubic); + } if (forward.length_squared() < CMP_EPSILON2) { forward = Vector3(0, 0, 1);