technical architecture.

Configurable Inverse Kinematics in unity at runtime

by on Jan.13, 2012, under Uncategorized

As demo’d in this video: OR3D tool walk thru the video is a bit on the older side, but it shows the IK fairly well.

the system is fairly simple rig that attaches as a script to the IK End Effector, and parses up the hierarchy collecting any bones that are tagged with a certain empty class (In my case called an EndJoint).

I collect bone joints at runtime after combining and configuring the hierarchy, and pass them into the CCD IK function as an array of unity transforms. the bulk of the code is taken almost directly from Jeff Lander’s game developer article describing the Cyclic Coordinate Decent (CCD) inverse kinematics algorithm, written in 1998,

the port can be downloaded from here:

3 Comments for this entry

  • Dave Buchhofer

    Followups, I’ve got a new interesting 6DOF robot visualization to build IK for with a lot more restrictions, so there shall be updates!

    Overall, its very easy to expand into 3 dimensions, its comparatively messy to add believable joint limits.

    for now, some light reading to get you started:

    Inverse Kinematics and Geometric Contraints for Articulated Figure Manipulation, Welman, Chris

  • Meer Imtiyaz Ali

    This is excellent project to draw layout softly and create 3d of that, wow so nice work of you. I am also work like that project but I am not able to draw 2d line with dimensions and flexible like your layout design, please can you help how to do that or can you give the sheet and code to draw 2d line with dimensions. Please.
    Thank you.

  • Nika

    Thanks for the algorithm. I used your IKSimple class for my project. I did a minor changes to better fit my project- spider tanks (boom! pew! pew!):
    1. optimization: used .sqrMagnitude everywhere instead of .magnitude because it’s not using square root computation. so much lighter for CPU.
    2. no need of .normalized vectors – Unity is handling them itself if needed. normalization is a beach to CPU as well.
    3. garbage collection was having huge spikes. It was caused by all the variables and arrays that were declared at the begging of the Solve() method. In my case I’m not going to change the bone structure on runtime so I’ve introduced a second method Init() that does all the initial computation and array declarations. it also stores the bones[] in a local variable instead of having it fed to Solve() every frame. For precision variable positionAccuracy I’ve commented out the computation and made it constant so it can be initialized manually per project. and finally, in the Update loop I’m checking for the target.hasChanged. this means I’m only executing the Solve() method if the target has moved.
    4. I’m struggling to introduce up vector
    5. I hate vector math
    6. no, I love vector math
    7. life is meaningless
    8. whales are in danger

    I’ve tested out the scene with 50 ik animations (all moving, none stationary) and had next to no performance drop.

    Let me know if you guys need this script. Hopefully will figure out today how to give the limb an Up direction…

Leave a Reply

Looking for something?

Use the form below to search the site:

Still not finding what you're looking for? Drop a comment on a post or contact us so we can take care of it!