Skip to content

armgit / godot

Public Imported from GitHub
0

Godot Engine – Multi-platform 2D and 3D game engine

Fix JacobianIK limitation method and clarify IK tip reachability

Silc Lizard (Tokage) Renew5adc2b540adb
diff --git a/doc/classes/IterateIK3D.xml b/doc/classes/IterateIK3D.xml
index aa7173373b0..9b0a6488da2 100644
--- a/doc/classes/IterateIK3D.xml
+++ b/doc/classes/IterateIK3D.xml
@@ -7,6 +7,7 @@
Base class of [SkeletonModifier3D] to approach the goal by repeating small rotations.
Each bone chain (setting) has one effector, which is processed in order of the setting list. You can set some limitations for each joint.
[b]Note:[/b] All the methods in this class take an [code]index[/code] parameter. This parameter specifies which setting list entry to return if the IK has multiple entries (e.g. [code]settings/<index>/target_node[/code]).
+ [b]Note:[/b] When [method set_joint_rotation_axis] or [method set_joint_limitation] is set, the IK tip may not reach the target. This occurs because IK calculates the path through iterations, and in some cases, it may hit a limit during the process and fail to resolve. In some cases, this can be resolved by splitting the IK into several [SkeletonModifier3D]s and setting the iteration order manually.
</description>
<tutorials>
</tutorials>
diff --git a/scene/3d/jacobian_ik_3d.cpp b/scene/3d/jacobian_ik_3d.cpp
index c5a29a78ae5..7f3e1bff0fd 100644
--- a/scene/3d/jacobian_ik_3d.cpp
+++ b/scene/3d/jacobian_ik_3d.cpp
@@ -61,11 +61,15 @@ void JacobianIK3D::_solve_iteration(double p_delta, Skeleton3D *p_skeleton, Iter
p_setting->update_chain_coordinate_fw(p_skeleton, j, current_head + to_rot.xform(to_tail));
int k = j - 1;
+ IKModifier3DSolverInfo *limited_joint_solver_info = p_setting->solver_info_list[k];
+ if (!limited_joint_solver_info) {
+ continue;
+ }
if (p_setting->joint_settings[k]->rotation_axis != ROTATION_AXIS_ALL) {
- p_setting->update_chain_coordinate_fw(p_skeleton, j, p_setting->chain[k] + p_setting->joint_settings[k]->get_projected_rotation(solver_info->current_grest, p_setting->chain[j] - p_setting->chain[k]));
+ p_setting->update_chain_coordinate_fw(p_skeleton, j, p_setting->chain[k] + p_setting->joint_settings[k]->get_projected_rotation(limited_joint_solver_info->current_grest, p_setting->chain[j] - p_setting->chain[k]));
}
if (p_setting->joint_settings[k]->limitation.is_valid()) {
- p_setting->update_chain_coordinate_fw(p_skeleton, j, p_setting->chain[k] + p_setting->joint_settings[k]->get_limited_rotation(solver_info->current_grest, p_setting->chain[j] - p_setting->chain[k], solver_info->forward_vector));
+ p_setting->update_chain_coordinate_fw(p_skeleton, j, p_setting->chain[k] + p_setting->joint_settings[k]->get_limited_rotation(limited_joint_solver_info->current_grest, p_setting->chain[j] - p_setting->chain[k], limited_joint_solver_info->forward_vector));
}
}
}