summaryrefslogtreecommitdiff
path: root/scene/3d
diff options
context:
space:
mode:
authorRĂ©mi Verschelde <remi@verschelde.fr>2021-10-04 20:26:55 +0200
committerGitHub <noreply@github.com>2021-10-04 20:26:55 +0200
commit19d090c32485f7579582d9741bea1b4f02c66ce5 (patch)
tree569c3357680755c2caa0b0a8ba3e6bed8d8e2bf5 /scene/3d
parent7fe0f4a426b8216d18e6b81e5c86b4f648a47b7c (diff)
parent92a79ace5b3e58933ecdb0e21e3c3402073979b0 (diff)
Merge pull request #53394 from TwistedTwigleg/Godot4_SkeletonIK_RegressionFix
Diffstat (limited to 'scene/3d')
-rw-r--r--scene/3d/skeleton_ik_3d.cpp12
1 files changed, 4 insertions, 8 deletions
diff --git a/scene/3d/skeleton_ik_3d.cpp b/scene/3d/skeleton_ik_3d.cpp
index 8d90aabfac..2e788051f4 100644
--- a/scene/3d/skeleton_ik_3d.cpp
+++ b/scene/3d/skeleton_ik_3d.cpp
@@ -291,14 +291,10 @@ void FabrikInverseKinematic::solve(Task *p_task, real_t blending_delta, bool ove
new_bone_pose.origin = ci->current_pos;
if (!ci->children.is_empty()) {
- /// Rotate basis
- const Vector3 initial_ori((ci->children[0].initial_transform.origin - ci->initial_transform.origin).normalized());
- const Vector3 rot_axis(initial_ori.cross(ci->current_ori).normalized());
-
- if (rot_axis[0] != 0 && rot_axis[1] != 0 && rot_axis[2] != 0) {
- const real_t rot_angle(Math::acos(CLAMP(initial_ori.dot(ci->current_ori), -1, 1)));
- new_bone_pose.basis.rotate(rot_axis, rot_angle);
- }
+ p_task->skeleton->update_bone_rest_forward_vector(ci->bone);
+ Vector3 forward_vector = p_task->skeleton->get_bone_axis_forward_vector(ci->bone);
+ // Rotate the bone towards the next bone in the chain:
+ new_bone_pose.basis.rotate_to_align(forward_vector, new_bone_pose.origin.direction_to(ci->children[0].current_pos));
} else {
// Set target orientation to tip