Monthly Archives: October 2014

Smooth IK setup

 

smoothingAlgs

IK smoothing is used to soften the motion of the IK handle as the chain approaches full stretch. It can be set up in the 3ds Max by position constraining the IK handle to two targets with distributed weights. One target should be the IK control curve(CC in gif) and the other, an object placed at the position of the first bone in the IK(FB in gif) chain. The position weights need to be set as script controllers. Given the nodes CC and FB, we can calculate smoothing using the following script for the influence of CC –

Exponential Smoothing:
            x = (distance CC FB) – Rmin
            y = x
            if x > 0 do
            (
                        y = (D – Rmin)*(1-exp(-x/(D – Rmin)))
            )
            r = (Rmin + y)/(Rmin + x)

Trigonometric Smoothing:
            x = (distance CC FB) – Rmin
            L = Rmax – Rmin
            y = x
            if x > 0 and x < L do
            (
                        y = (D – Rmin)*sin(90*x/L)
            )
            r = (Rmin + y)/(Rmin + x)

Rmin is the minimum radius of influence beyond which smoothing starts to take action. Rmax, used only for the trigonometric method and it defines the maximum distance CC needs to be from FB for the arm to be completely stretched out. These values are shown in the figure as the blue curved lines (which are actually circles with the center at FB)

The weight influence of FB can be set as 1 – Influence of CC.

I personally prefer the trigonometric method because it contains the extra Rmin attribute, giving the user more control. Also, it has a more natural motion as CC approaches Rmax.

Input.GetAxis vs Input.GetAxisRaw

I recently started getting into some Unity programming with C# and was working on a character controller script to make a simple box move on a 2D plane. I was using the Input.GetAxis method to read the input from the keyboard. After a little bit of playing around, I wasn’t satisfied at all with the way the character was moving, it seemed like there was a little bit of delay when the key was pressed and also when I let go of a direction key, the character still moved a little bit as if it had some momentum. None of the physics settings seemed to fix this issue. After a bit of digging around, I found out that it was not the physics that was causing the sluggishness and over shooting, it was the input method. The Input.GetAxis method contains an inbuilt smoothing filter which automatically smooths out the key press. This means that the function won’t give an immediate full response to the key press, the return value will gradually increase from 0 to 1 as the key is pressed and decrease from 1 to 0 as the key is let go. I personally find this smoothing quite annoying and it feels sluggish for the kind of movement I want. The alternative is to use the Input.GetAxisRaw which gives a 1 when the key is pressed and a 0 when it is not. Simple and straight up.

Reverse FK rig

This rig was skinned to a snake like creature which needed to perform actions like slithering, rearing its head and whipping its tail to attack. A regular spline solution that is commonly used for these kinds of movement was just not cutting it, the involved animator insisted that a much higher quality of animation could be achieved via FK follow through technique. The problem? To animate follow through in a slithering animation, the FK hierarchy should go from the head(parent) to the tail(last child) while, for a rearing animation, the FK hierarchy would need to go in a reverse direction – the rig would need to have FK controls working in both directions. Here is a demo of my solution, the Reverse FK rig:

 

The only drawback that this rig faced was that the ‘Mid Point’ can’t be keyed in the middle of the animation. It breaks the existing animation of the control curves since the snapping option affects transforms their previously inactive parent objects. This was easily overcome by breaking apart the animation into separate files at the frame when the Mid Point changes. These animations were later stitched together in code.