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
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 15 additions & 3 deletions scene/3d/path_3d.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
Expand Down