Skip to content

Fix JacobianIK to apply gradient correctly#112573

Merged
Repiteo merged 1 commit into
godotengine:masterfrom
TokageItLab:fix-jacobian-gradient
Nov 13, 2025
Merged

Fix JacobianIK to apply gradient correctly#112573
Repiteo merged 1 commit into
godotengine:masterfrom
TokageItLab:fix-jacobian-gradient

Conversation

@TokageItLab
Copy link
Copy Markdown
Member

@TokageItLab TokageItLab commented Nov 9, 2025

The distance gradient ratio was not applied to angle correctly (it should be divided by powered 2 of the length), resulting in excessive rotation. And applying angular_delta_limit clipping at an earlier stage allows users to prevent excessive rotation at their discretion.

Also, the document incorrectly states “pseudo inverse matrix.” The correct method is the "Jacobian transpose" method. Fixed. cc @jitspoe

Before:

jacobian_ik

After:

Godot.Engine.2025.11.09.-.16.07.52.04.mp4

@TokageItLab TokageItLab force-pushed the fix-jacobian-gradient branch from 93c9f88 to 069206b Compare November 9, 2025 06:55
Copy link
Copy Markdown
Contributor

@lyuma lyuma left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I found a paper explaining the idea of squaring the delta angle from the Jacobian Transpose.

https://www.cs.cmu.edu/~15464-s13/lectures/lecture6/iksurvey.pdf section 5

So I'm inclined to agree that this change could help.

That said, I am concerned about the possibility of head_to_effector having length units (as opposed to a unitless ratio). From what I can tell, this variable is the difference between two values in p_setting->chain, which themselves are assigned directly from get_bone_global_pose(...).origin, which are in units of meters. However, get_bone_axis is normalizng the returned axis, producing a unitless value. Hence, the resulting angle used in to_rot appears to be in units of 1/length

I'd like to make sure that the IK produces different solutions between two equivalent skeletons with different uniform scales (for example, both a 1 meter humanoid reaching a target 1 meter away, and a 100 meter humanoid reaching a target 100 meters away should produce the same angle). During testing, it is common to use default cube or human scale skeletons with roughly 1 meter length head-to-effector, so it might obscure bugs that happen at very large or very small scale.

I'm okay trying this PR to solve issues at human scale, but we might want to test very small and very large skeletons to make sure that the distance between head and effector is properly divided out.

@TokageItLab TokageItLab moved this from Ready for review to Approved, Waiting for Production in Animation Team Issue Triage Nov 11, 2025
@TokageItLab TokageItLab requested a review from Repiteo November 13, 2025 00:11
@Repiteo Repiteo merged commit 0b5ad6c into godotengine:master Nov 13, 2025
20 checks passed
@github-project-automation github-project-automation Bot moved this from Approved, Waiting for Production to Done in Animation Team Issue Triage Nov 13, 2025
@Repiteo
Copy link
Copy Markdown
Contributor

Repiteo commented Nov 13, 2025

Thanks!

@GeorgeS2019
Copy link
Copy Markdown

follow further discussion of godot demo on 3D IK here

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

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

4 participants