XaiJu
Megan Fox
Megan Fox

patreon


Leg/foot IK (extra code details)

This is just explaining the FootTrace function, and the why behind the Z instead of the XYZ when doing the traces.

What's With Z Instead Of XYZ

First, let's explain the why. The gist is that you want to distort animation space instead of a more literal pin-foot-to-point. The reasoning is simple: distorting the animation space is continuous. It'll look right regardless of animation timing, framerate, blending, keyframes, anything.

If you try to mark a trace point, and use, say, the Z distance to blend from normal animated foot position to a snapped-to-ground IK'ed position? You're going to introduce effective lerp frames that will look for all the world like the ground is steel and you're wearing magnet boots. The feet will anticipate the ground when in proximity and accelerate down, and stay stuck to the ground a bit longer than they should, eventually "popping" off. Don't believe me? Try it! It's pretty simple to implement this function both ways in ControlRig, and it's a good exercise anyways. Look close. You'll see what I mean.

There are some clever ways around the magnet look that I may dig into in future posts. For the moment, assume they are both outside the scope of this post and not necessary. The only reason you're going to want to go fancier than the Z-offset method is if you want foot planting, which a ton of AAA games don't even bother doing. Just, trust me, the Z-offset method will get you extremely smooth looking IK. Start here. You'll already look better than. Um. A lot of very expensive games.

The Function Innards

If you're doing this, you almost certainly won't have both these lines. Unless you have clown shoes, like I do. I have to twice twice, because, oh my godddddd bird feet in clown shoes, so I have to run it twice and pick the most extreme of the two hits. Worth it, though!

Anyways, that aside, this is straightforward. Get the foot bone position, trace down however far (in my case 50), sphere trace, yada yada, that's your trace position.

Now there is a clever bit you get with the dual trace, and that is smoother orientation. You wouldn't think simply averaging the normal from your heel trace and toe trace would work, but. (It totally does)

So maybe you do want to do dual traces if you really want good, smooth, foot rotation? Remember, the better your foot rotation is, the better the resultant leg IK will be. Not necessarily true with oldschool IK methods, but if you're using Fullbody IK? This rotation is as important as the pole-vector position used to be, so, keep that in mind.

Oh and just so you can see the function arguments, tadaaaa. Nothing fancy, just, completeness's sake.


Leg/foot IK (extra code details)

More Creators