NokiMo
Megan Fox
Megan Fox

patreon


Leg/foot IK with mix of old and new techniques

What you're looking at here is UE5 ControlRig, though all of this should work fine in 4.27 too. It looks big and complicated, but, really it isn't!

BTW, I went back and forth on how the heck to share this stuff, and settled on "screenshots?". Let me know if anyone hates this, it's the most durable way I'm aware of for sharing BP, as annoying as it is.

Anyways, let's begin!

Step 1: Setup

Most ControlRigs will start with something like this. The goal here is to establish controls at the points in the skeleton you intend to drive with logic. Now in my case, I'm driving this all with FullBodyIK, which has some cool advantages.

Step 2: FullBodyIK Explanation

With normal IK, it's limited to driving a few bones, meaning if you drag down on your foot control, it's only ever going to be able to move your upper and lower leg. 2-bone is the standard. The rest of the skeleton may as well be locked in cement. But I use FollBodyIK, which is a new node they added in UE5 and, I believe, back-ported into 4.27. Which means I can drag the whole body down by just pulling on the foot. Super handy!

Now, the downside of that is, with certain exceptions that we'll get to in a moment, these controls pin bones, meaning you lock them in place as far as FullBodyIK goes. IK will drive what the bones do between these points, but can't move these controlled bones, because your controls take priority over what FullBodyIK might try to do.

Where this gets weird is, say you want to drive your head with IK to handle, I don't know, getting thwocked in the face with a big meaty fist. But you also want to make foot IK ground your feet as usual, AND you want your foot IK to be able to drag the whole body down for when your person steps into a hole.

Well, if you have a control on your head, your feet won't be able to pull your body down like that. You'll pull your leg down, your body will go taught, and your head will stay stubbornly wherever you put the control.

But don't worry, I'll show you how to work around that!

Step 3: Initialization at the start of Forwards Solve

(Everything from here on works off the Forwards Solve node in your ControlRig)

First up, we move all the controls to match where the bones presently are. Once upon a time, we used IK Bones instead of these controls, and the IK bones were your virtual skeleton points that you moved around to be your bone-position targets and such. Now? Controls serve the same purpose. You don't really need IK bones anymore.

Then we set a blend-value based on how high above "ground" the foot currently is. Remember, animations exist in a space that tends to treat Z of 0 as walking on the ground, so we can treat a Z greater than 0 as indicating that foot has been animating to be mid-step up off the ground.

In this case, we use that to blend in/out our control of foot rotation, so that we only override the foot orientation when we're pretty sure the foot has been intentionally animated to be standing on the ground.

Now we're to the actual meat of the logic. First, do the foot traces. These are what figure out where the ground is / where the foot needs to be.

$3+ tier folks will get the contents of the FootTrace and other functions here, but the gist is just that you're figuring out where the ground is. The outputs are the Z where we want to put the foot, the Up-Normal which dictates the foot's rotation, and whether or not the foot trace actually hit anything. If the foot trace didn't hit, then we're not gonna apply the IK at all, obviously.

Step 4: Rationalization Of IK Technique

Now here's where need to talk about what that target foot Z actually is, and why it's just Z. We are NOT setting the target foot position. I know that sounds weird, but, think this through with me. If we were pinning the foot position every single frame, we'd be overriding the walk animation. If we tried to fade from (arbitrary animated position) to the traced X Y Z, you'd get this kind of magnet suck-down feel to your steps.

So what's the solution? Easy! We're just treating it as a spatial deformation!

WAIT don't run away I swear it really is easy. Just add the target Z we extracted to whatever the animated position of the foot is. That's it. I'll do a longer post about this to the $3+ people explaining the logic, just, trust me for now that this will get you a cleaner result than alternatives.

The main takeaway is, that just being a Z isn't an accident, and replacing that with a version that gives you a specific X Y Z of the trace (and you fade it in/out the same way you do the foot rotation) likely won't be an improvement. Try it both ways if you don't believe me.

Step 5: The Meat

This is where most of the logic lives. It's wide, so you'll have to kinda squint and stable these together in your brain parts.

Step 5.1: Tweening

Rather than just setting the target IK positions or rotations, we want to blend from the last target to the current. That keeps it smooth. Do this for both position and rotation, but the blend type you use for each will be different, so don't set everything up assuming you'll be using the same blend rates for both. Set rot blend and pos blend up to be tuned independently.

Step 5.2:  Pelvis Adjustment

Whichever foot has the least amount of IK offset? Apply that amount of IK offset to the pelvis instead. This keeps the body from being bent into completely unnatural poses. Like if both feet are standing on a rock, you probably want mostly-straight legs and you're just, up higher, standing on the rock, right? Not two bent legs so that your pelvis is the same height as it was before you stepped onto the rock.

Step 5.3: Apply the IK offsets to the foot controls

Now adjust the foot controls up/down based on the Z offsets we extracted from the traces earlier, and do the same to the pelvis. Also apply the foot rotations.

Step 6: Where The Rubber Meets The Road

Remember way back earlier when I explained about how controls would kind of peg FullBody IK, and how it couldn't move the controls you set? This is how you get around it.

First, move the pelvis BONE based on all that IK calculation you did earlier. You're basically doing manual pelvis IK here. Then, feed only your foot controls into the FullBody IK, so that it can shift things from there however it feels it needs to. Since you already set the pelvis bone location, the FullBody IK will be working with an already adjusted skeleton, and it'll all play roughly nice together without the pelvis control blocking the ability of the foot controls to shift body pose around in a more natural way.

If you were grabbing out the head to knock it back because of a punch but also wanting to do foot IK? You might do similar here. Heck, you might run FullBody IK twice. Once with the head control to knock the head back, then again with just the foot controls to pull it up/down for grounding.

You can also solve some of these problems with the "Spaces" that ControlRig lets you define. The idea there would be that the space the head knock-back happens in is childed under the space of the rest of the body, so you're free to move the pelvis and feet around and it'll just drag the head control/head space along for the ride. That's beyond the scope of this little blog though, sorry! I barely understand Spaces myself. Their UI sucks. I hope it gets better, heh.

Leg/foot IK with mix of old and new techniques

Related Creators