IK, Constraints and Interpolation

Chuji 8 years ago updated by tmpxyz 8 years ago 6

Hi, I have been having a lot of issues using IK and getting smooth interpolation, mostly I am getting limbs spinning much beyond 360 degrees, and requiring a lot of extra work to clean up the curves.

It occurs whether using Euler angles or Quaternions, the new IK system with constraints or the old IK system. In edit mode or outside using CCDSolver components and helper markers.

This post is going to be dedicated to some odd behavior using the CCDSolver method for IK and Constraints.

Here is the test scene with required extras. http://s000.tinyupload.com/index.php?file_id=73674831954535073720

Inside you will find the test scene "Adv_ConstraintForWalk_Bugged" which is just a slightly edited Adv_ConstraintForWalk scene set up for animation.

You will also find the animation "InterpolationBugged" and the controller "Robot Kyle G".

Now the Controller is not linked to the animation, so throw the animation in there.

In the Hierarchy, open up the game Object "Robot Kyle M -> Hips -> LeftUpLeg"

Head into the Animation view and select InterpolationBugged animation.

1. Note the LeftUpLeg bone rotation values.

2. Now start dragging the animation Key frames from start to end and then all the way back to start.

Repeat step 2 a few times and you will notice that for every repetition the rotation values such as Y will start increasing/decreasing as long as you repeat the process. (I've had it occur on Z aswell, only X that it does not occur on).

This causes a lot of issues when you just want to go over the animation progress scrolling back and forth through the key frames. Once you decide to bake using the AnimationBaker, those ridiculous values of rotations get used as keys, and the interpolation goes completely haywire, with limbs rotating thousand of times between key frames. It slows the animation down a lot, needing to spend a lot of time having to clean it all up.

The animation in there was just me fiddling trying to reproduce the issue. It doesn't seem to take much, just create an animation moving forward for a moderate amount of keys, and the bug will appear. The more the limbs rotate, such as upper leg, the quicker it will appear. The increase of rotations seems to be at a very specific point in the "InterpolationBugged" animation when going beyond about 0:35 and then back. Lack of RightFootTarget.position? No idea, but then why is it occurring on LeftFoot (I have managed to get it on RightFoot aswell). I get the same kind of issues animating my own model (Which is what led me to test it with the generic Robot Kyle model).

I hope that this post was of any worth and that the root of the issue can be found and solved.

Best regards.

Just wanted to add, this is with latest version of Skele (1.9.4), and version 5.3.3f1 Unity.

I also saw other users having similar interpolation issues

Here, using just regular FK: http://forum.unity3d.com/threads/skele-character-animation-tools-cutscenes-and-animations-authoring-tools.240996/page-15#post-2599103

Here, also seems to be using FK: http://forum.unity3d.com/threads/skele-character-animation-tools-cutscenes-and-animations-authoring-tools.240996/page-15#post-2571004

Now the bug I presented is slightly different, yet the interpolation errors are a common factor, I don't know if they are any related. The way their limbs interpolate using FK seems to be completely Unity internal reliant. Still odd behaviours.

Under review

Hi, Chuji,

Thanks for the feedback :)

1. Once you decide to bake using the AnimationBaker, those ridiculous values of rotations get used as keys.

Tried reproducing here and I can see that the euler angles go up to 10000+ degrees here.

But as I'm using 60 sample-rate fully baked clips, the rotation didn't go wild.

I don't know why Unity would record the keyframes that way, but I could just normalize the rotation angles for the baked clips into the range of [0,360).

That should be easy to make, will update the package this week.

( if there's some isolated way to reproduce this without Skele then maybe I could report to Unity asking them to fix the keyframe recording code. But so long I cannot find that )

2. I also saw other users having similar interpolation issues

No, they look just usual unexpected interpolations. Much different from the issue you posted.

For unexpected interpolations, I would suggest same solution like in blender:


(1) use Quaternion interpolation;

(2) add more keyframes in middle;

Best regards, Be creative,

1. Thank you very much, I believe keeping them in the range of 0 -> 360 could solve some issues.

Not sure what you mean by why Unity would record the keyframes that way. Isn't it skele that re calculates the IK targets/rotations/positions when using CDDSolvers every time you drag the keyframs back and forth causing the prefab model to get odd high euler values before you even start recording key frames? I mean this is something that occurs way before even trying to record keyframes. It's as if Skele thinks we are manually moving the targets once more when in fact we are just previewing the animation, and then messes up the calculations. Keeping them in range 0 - 360, could possibly just be a quick fix that ignores the underlying cause of it. But worth a shot to see if it actually fixes the bug.

2. Yeah I figured it was normal and just the way unity interprets the interpolation when insufficient information in keys. Though my issues haven't been in FK, only when using IK, but thought it might have been worth mentioning.

Best regards!

Ah, yeah, you're right. I've made some test on CCDSolver and it does boost up the euler angles a lot during the rotation. that's weird, I should only used quaternion and transform.rotate during the procedure.

Anyway, I'll make some investigation into that.

For now, you could update to Skele v1.9.5 I just updated, I added a "Compress Angle" button on AnimationBaker.

After baking clip, you could use this to clamp eulerAngles of all keyframes to reasonable range.


Hmm, after some debugging, I found out what happened. it seems that setting transform.localRotation could result in instable localEulerAngles, an interesting gotcha.

e.g.: setting Quaternion.identity to transform with <0,0,0> ==> localEuler = <0,0,0>;

but setting Quaternion.identity to transform with <0,-190,0> ==> localEuler = <0,-360,0>;

Thanks for your report, this fix would get updated soon.

This fix is included in Skele 1.9.5p1, should be online in hours.