Skip to content

Commit

Permalink
Fixed SkeletonIK not rotating correctly when solving
Browse files Browse the repository at this point in the history
  • Loading branch information
TwistedTwigleg committed Oct 4, 2021
1 parent 66ab3ce commit 92a79ac
Showing 1 changed file with 4 additions and 8 deletions.
12 changes: 4 additions & 8 deletions scene/3d/skeleton_ik_3d.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 92a79ac

Please sign in to comment.