Inverse Kinematics


Fixed an issue where nodes with multiple children did not calculate rotations correctly.

My TODO list is getting very small. It’s mostly gruntwork from here on out. I’ll be writing the script bindings now and submit my first pull request. I can work on constraints for future versions.

 *  - Add support for manually updating initial pose.
 *  - Script bindings.
 *  - Optimise.
 *  - Profile.
 *  - Documentation.
 *  - Support for "stretchiness" with min/max lengths.
 *  - Support for "stiffness" factor, describes how well a bone rotates.
 *  - Apply bullet constraints to joints.


I’ve just tested and it works great :grinning:

For target nodes, I think it would be better to use node ID instead of node name in the Editor, to match every other components (Constraint, Constraint2D, OffmeshConnection…) behavior (and to allow simply dragging the node in the target slot).

I’ll do some more tests, and report feedback. Let me know if I can help in any way :wink:


You should setup a patreon so we can all donate for your amazing work. :slight_smile:


I’m happy to report the first version has been merged into master! All features you’ve seen in this thread are now available.

If you have questions, feature suggestions, or bug reports, I look forward to hearing from you. I will be actively maintaining this.

There is a new sample, 45_InverseKinematics, that you can look at. Here’s what it looks like:

The next thing I will be working on is @1vanK’s suggestion to add constraint support.


Congrats! The IK samples in C++, AngelScript, and Lua are also available in Web platform now.


The papers I’ve found on FABRIK aren’t very clear on how constraints should be implemented. Sometimes they’re even cryptic. Nevertheless, I think I’ve been making some progress.

My first attempt at implementing constraints failed. I first thought you could apply constraints to the entire tree every iteration, but as you can see, the algorithm no longer converges. (Here, I’m trying to force one of those joints to always be straight no matter what, but it seems he’d rather remain gay).

I’m now working on my second attempt where constraints are applied per node as the tree is being iterated. The math is cumbersome as it involves computing joint rotations and transforming to and from local space.

It looks like this could work. I think I have to apply constraints during forwards iteration as well as during backwards iteration (right now it’s only during backwards iteration). Calculating local joint angles is going to be a lot harder in forward iteration, I’m not yet sure how to tackle this.

The nature of the FABRIK algorithm makes constraint support inherently inefficient, because FABRIK has no need for joint angles and works entirely in global space. Joint constraints require joint angles in local space. There is an unfortunate performance penalty, which is fairly evident by just looking at the code.


Well, IK constraints were always different from normal contraints (look at how Blender handles IK).
I think you should make universal constraint matrix out of all constraints and apply just that.
That will be a bit more efficient in loop. The other approach is to not require constraints to be justified at all times,
just get to the point iteratively. Just my $.00002 :slight_smile:


I don’t think one giant constraint matrix is suitable in this situation. The constraints are being applied during iteration, meaning the tree is in a partial state of being solved. But if you want we can discuss it in more detail and I can explain the algorithm more closely to you.

I tried applying all constraints at once after iterating the tree every time, but it caused the algorithm to diverge.


Well, I don’t want to disturb you, I’m just passing by. I just remember all these IK lectures telling that you either
solve constraint analytically (all at once) or use Jacobian matrix and solve numerically (iteratively solving
differential equation system).
But what I wanted to say is that constraints for IK in Blender are different from other constraints
and they work independently of constraint system. I think this is way to go. Also I think you’d want only
angular constraints at first.

Also, is it possible to use sparse chains in your IK system, i.e. I want the system to know about a set of bones,
but not touch others. I.E.
an arm consists of bones AB-CD-E (fingers omitted). I want A and C to be moved by IK, others should
just rotate together with parents not touched by constraint. Will it work?


There are some good resources here (which you may already checked): and (with a demo here)
However I didn’t succeed in implementing them.


Is there an example on how to do aim offsets? Not only a look at constraint, but something like this:


Seems simple enough. He’s created a number of predefined poses for the different angles the gun could be at and then he’s blending between those poses when crossing a threshold (first part of the video).

Since you know the target direction, you can slide the gun around on an imaginary sphere depending on the direction, calculate the hand positions and rotations, and use IK to move the hands there.

I’m still working on constraints whenever I have free time, but this should be possible without them.


Sorry if i’m being too much of a newbie, but do you have a link with an example of pose blending in Urho? I’ve been trying to use pose blending to improve several animation in my game, heavily inspired by this, but i can’t get my head around it.


@smellymumbler have you looked at IK demo with current Urho? it shows sort of IK + animation blending.

If you want to blend between animations, look at AnimationController and use layers. For more complicated cases use AnimationState (s). It is very sad there’s no really goood example on these, but if you look at Character demo,
you might understand part of it then go back and ask more specific questions.


I did. But, at least in my head, the animation blending idea does not really work for what i’m aiming for. You have two different layers and you have a blending amount between the two. This is nice: you can make a running animation turn into a walking animation, smoothly, based on user input.

However, what i’m aiming for is a little different: i have two poses: a standing one and another one in full run. My animation clip is the result of an interpolation between those two poses + input from the user. Are those two different layers? Can i blend them normally?


You can blend on the same layer too. You will always use a combination of blending on the same layer and additional layers. I know the system explodes the brain, but I was enlightened after looking some GDC presentation on youtube
about layered animation, I dn’t remember title. The idea is that you need to transit from one animation to another on
the same layer, so just play new pose animation on the same layer at appropriate time and it will blend into it.
Probably not best thing performance-wise, but it should work.


And also, if you really understand presentation you use for inspiration, please share, I was not able to understand their way.


Blending there is just done on arbitrary response curves between frames. (Desmos graphs for a few MKCB curves:

The “survey wheel” is just circumference vs. distance. Given a distance traveled the degrees turned can be found given the circumference (or diameter/radius -> circ) which drives animation timing.

The “ticks” in the wheel are a bit of a red-herring that looks more important than it is, they’re just visual helpers for where the timings are, the circumference is the important part. The stroke cycles of each leg are overlayed on top of each other into a final gait cycle in the wheel. (Girard, Computational Modeling for the Computer Animation of Legged Figures goes into the nitty gritty as far as actually simulating but most of the math is still valid for finding cycle timings from existing animation).


Well, i was trying to achieve this differently by timing lowest leg position and change animation speed to
minimize sliding. The problem is that I failed somewhere and could not achieve the goal this way.
I don’t want root motion animation, it is too unflexible… Procedural walk loop looks so promising but I was not able to
get 60fps as it was too many calculations per frame…


If your goal is to recreate what the Wolfire people achieved with Overgrowth: Let Urho3D do the heavy lifting for you. You don’t have to implement blending between keyframes, let Urho3D’s animation do that.

  1. Create a walking animation
  2. Create a running animation with the same length as the walking animation (important! If they’re the same length you can easily synchronise them)

Now you can control the speed of both animations depending on stride (the “conveyor wheel” approach) and you can blend between both animations (using layers) depending on the player’s velocity.

Overgrowth isn’t using IK to prevent foot sliding; they still have that problem, it’s just well corrected. They do use IK to align the foot vertically so it’s always touching the ground.