Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix forward calculation in PathFollow3D for the position at the end of the curve #50986

Merged
merged 1 commit into from
Aug 3, 2021

Conversation

raulsntos
Copy link
Member

Fixes #50973

The issue was, when the PathFollow3D has its unit_offset set to 1.0 (or offset to the length of the curve), that is the final position at the end of the curve, the rotation was being reset. This was happening because of these lines:

godot/scene/3d/path_3d.cpp

Lines 115 to 122 in 60eb508

if (rotation_mode == ROTATION_ORIENTED) {
Vector3 forward = c->interpolate_baked(o_next, cubic) - pos;
if (forward.length_squared() < CMP_EPSILON2) {
forward = Vector3(0, 0, 1);
} else {
forward.normalize();
}

When we are the end of the curve, the interpolate_baked method returns the same Vector3 for offset that it does for o_next so when the forward vector is calculated in line 116 the result is Vector3(0, 0, 0) which is not valid so in line 119 it is set to Vector3(0, 0, 1) which is the global forward direction and this produces the effect of having the rotation reset.

To prevent this, this PR also interpolates a previous vector o_prev so if we are at the end of the curve, we can calculate the forward vector with the previous position, in pseudo-code:

if o_next - offset != 0:
	forward = o_next - offset
else:
	forward = offset - o_prev

@raulsntos raulsntos requested a review from a team as a code owner July 28, 2021 20:09
@Calinou Calinou added bug topic:3d topic:core cherrypick:3.3 cherrypick:3.x Considered for cherry-picking into a future 3.x release labels Jul 28, 2021
@Calinou Calinou added this to the 4.0 milestone Jul 28, 2021
@akien-mga akien-mga merged commit 0f8cba2 into godotengine:master Aug 3, 2021
@akien-mga
Copy link
Member

Thanks!

@akien-mga
Copy link
Member

Cherry-picked for 3.4.

@akien-mga akien-mga removed the cherrypick:3.x Considered for cherry-picking into a future 3.x release label Aug 3, 2021
@raulsntos raulsntos deleted the fix-path-3d-end branch August 3, 2021 09:38
@akien-mga
Copy link
Member

If this is cherry-picked for 3.3, #51358 should be included too.

@akien-mga
Copy link
Member

Cherry-picked for 3.3.3.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

PathFollow with RotationMode = Oriented is wrong at unit_offset = 1.0
3 participants