IK Foot Placement Setup

IK Foot Placement Setup

After some time i want to share my IK foot setup working with default UE4 mannequin.
At beginning i was planning to release it on marketplace but i’ve changed idea.
I have spent one week to create this project and two day for writing this tutorial.

Main features are:

  • Auto adjusted collision capsule height.
  • Performance optimized.
  • There is no strange legs behavior when running.

Preface

Starting with a little bit of theory, I will assume that you have a basic knowledge of what IK (Inverse Kinematics) is.
If not, spend some time to read IK Setup from Unreal Engine.

Most of users dealing with IK  on Unreal Engine don’t know how Two Bone IK work and what “Joint Target” is.

Like as Ray Arnett saw on answer hub

Joint Target is basically the equivalent of a pole vector in Max or Maya. For example, on a leg or arm IK setup, the knee or elbow will aim at the Joint Target.

Ray Arnett
PixxiePane Rig

Look at the left picture, i’m just translating a bone that act like as our Target Joint in UE, Pole Vector in Maya or Pole in Blender

Just to clarify, i will not using  the PixxiePane rig for this tutorial though it is much better for IK animations inside the engine.

Adding Sockets

Now we can proceed with the practical tutorial.
So, lets start by adding sockets for each foot. Leave relative location and rotation at zero values and names like as engine default, so foot_lSocket and foot_rSocket.

Animation Blueprint

Next we will jump to our Animation blueprint, so that we can define variables and setup nodes.

First of all define this variables:

TypeVariable NameDefault Value
vector3LeftJointLocSet to a value that look good in anim preview
vector3RightJointLocSet to a value that look good in anim preview
float LeftEffectorLoc0.0
floatRightEffectorLoc0.0
floatHipsOffset0.0
rotatorLeftFootRotation0:0:0
rotatorRightFootRotation0:0:0

Then place and set nodes as following images:


RightEffectorLoc is multiplied by -1 because the right_l bone in the mannequin character is mirrored and so flipped.

Now in my case Joint Target values are (X=-14.463602,Y=28.193642,Z=-15.975664)for left foot and (X=-16.883377,Y=26.909676,Z=14.823689)for right foot.

In your case and for some reason your values can be different, like as i saw previously try to adjust these settings to achieve a good result in the animation preview.

Character Blueprint

Define variables:

TypeVariable NameDefault Value
nameIKLeftSocketfoot_lSocket
nameIKRightSocketfoot_rSocket
floatIKTraceDistance50.0
floatIKHipsInterpSpeed7.0
floatIKFeetInterpSpeed13.0
floatIKCapsuleHalfHeightdefined in construction script
floatIKAdjustOffset2.0
floatIKTimeout0.5
boolIKOptimizedtrue
refAnimInstanceAnim Instance BP

Construction Script

In construction script we will store the default capsule half height to use it later.

Event Graph

I always use to store worlds delta seconds within a variable instead calling “Get World Delta Seconds” as a good practice so that can reduce function calls and reducing connections between nodes.

At this point i will not immediately show the content of IK Graph, instead i will show every IK functions used.

IKFootTrace

Notice the three local variables with the comment bubble, you can also omit to define these local vars connecting function inputs directly to destination. So, what this function do is casting a line trace from the middle of capsule for Z location and from X and Y foot socket’s locations straight down until to the bottom of the capsule and then subtracting the TraceDistance (Distance) variable value.

Then, if there isn’t a valid hit the function will return just a zero, otherwise the end trace location is subtracted from the trace hit location and successively from TraceDistance, to taking only the distance value from the socket to the hit location.

Then we just add a positive or negative value for adjusting the foot offset because capsule stand always 2 or 3 units higher from the underlying object. This value could be different if you are using different animations or character meshes.

Outputs are simply the foot offset and the impact normal, useful when we will go to adjust the foot rotation to match the floor slope. See next function

NormalToRotator

This function will convert the trace impact normal vector to rotation.

IKUpdateFootOffset & IKUpdateFootRotation

Not too much to say here, just two utility function to update foot offset and rotation smoothly.
NOTE: EffectorVar and RotationVar variables are passed by reference.

IKUpdateCapsuleHalfHeight

Here we can see that this function take two parameters as input: Hips Shift and Reset To Default.
Basically when the hips/pelvis bone is shifted down there is a significant distance between the top of the collision capsule and the top of the mesh’s head. So the height of the capsule will be always proportionally related to the hips bone translation.
So, the hips offset is “absolutized”, divided by two because capsule height is set by it’s half value and then is subtracted to IKCapsuleHalfHeight defined in construction script.

IKResetVars

Function to smoothly reset variables to default or zero values, called when character start moving, useful to reduce brute camera movements also.

IsMoving (Pure)
IKUpdate

This is the big part of this tutorial. So keep ready! Like i saw before, notice the “local var” bubble

IKUpdate Part 1
IKUpdate Part 2

Before updating foot effectors in the animation blueprint, Left and Right foot offsets variables are still unclamped. Here we are taking the min value between footoffsets and zero. The smallest value will be used to translate hips bone.
Then, when we have the hips offset, we can update capsule height with the new value.

IKUpdate Part 3

We are subtracting the hips offset value to each foot effector value. This because if hips bone go up all skeleton go up and, because of this, foot too. So subtracting it’s value to foot effector value will keep foot bones at the established position calculated in the Part 1 of IKUpdate function.

IKUpdate Part 4

The last part of this function, created mainly for optimizing performances.
We’re just checking that the current foot effector location value from animation blueprint is the same as the one that has just been calculated previously. When both values are equal the custom event DisableIK will be fired.

IK Graph

Here we go. Now i can show you the content of this graph. It’s just a logical graph.

IK Graph Overview
IK Graph Part 1
IK Graph Part 2

Here we are just checking some conditions to check if character is moving or is turning.
Practically IK work only when character turn on itself even if it is not moving. EnableIK is another custom event in combination with DisableIK previously mentioned.

IK Graph Part 3

In this part we can see the gate and events that allow to enable or disable IK.
DisableIK is delayed because if IK will be disabled instantly UpdateIK will not have enough time to update foot locations. IKTimeout variable is the time to wait before disabling IK.

And that’s all. This is our result

Final Thoughts

I think that it could be more optimized, it need only a good refactoring. Maybe i could extend this project to hands when i will have time.

32

Published by komahz

Hi, my name is Alessandro, I live in Italy and I love everything related to videogames and 3D. My first job is web developer, i use PHP, Perl and python. In my free time I like to experiment with UE and from the time I’ve created this blog I will write some tutorial to share my knowledge. If you believe that some of what i will write can be useful for your project feel free to think to buy me a coffee.

42 comments on “IK Foot Placement Setup”

  1. Hello ! Amazing tutorial ! I was just wondering what are in the EnableIK and DisableIK 😉 Also how you use your graph (IKGraph) in the Event Graph ?
    Final question : what are the Set Float (by ref) components ? And whats inside ? 🙂
    Once again, amazing work !

    1. Hi Timothé and thank you! EnableIK and DisableIK are just two custom events. SetFloatByRef is a predefined macro in the UE. All is written in the tutorial. I know, it is a bit long but all is explained very clearly 🙂

      1. Thanks for your quick reply ! I’m might sound stupid, but I really can’t find Ste Float and Set By… How do you use them ? I don’t find them, even though I searched for them during half an hour… (Search in content browser for “Set By, Set Float, Float, Set, Macro, Set By, Ref, References, etc…)

    2. I think that you’re trying to create a new node from nothing. Try to drag off you pin from the desired variable , turn on on “context sensitive” and then search for “set by ref

      1. Hey !
        Thanks for all ! I finally found it ! You were right, I tried to create a node from nothing ! Once again, thanks for all !

      2. Was the set float (by ref) removed in an update to the engine or something? Even when dragging from an existing pin (I’ve tried all of them), I can’t find set float (by ref) in the list.

          1. I did. It turned out the problem was just me being sloppy. I realized I didn’t set Effector Var to Pass-by-Reference. Checking that box fixed it. 😛

            Quick question though. In the IKUpdate function, is that a Sequence node on the left in the first image? The writing is too small to make out and I just wanna make sure I’m using the right node.

  2. Hi, I followed all steps and I’m using UE 4.14.2. Should it work also with UE 4.14.2? At moment I’m not able to see it working.

    Ciao, ho seguito passo passo il tutorial e non funziona. è possibile che sia un problema di versione?

  3. The first of all the congratulations for the tutorial.
    Now the question, after completing all the steps of the tutorial, when I give play, my player is buried pelvis down and I can not solve the problem.

    Could you help me?

    1. Hi thank you, first of all can you please post a screenshot from the anim preview window? Also be sure to set all variables with the predefined value

      1. Here is the photo of the ANIMBP:
        http://imgur.com/a/aVJ1W

        I think I should miss some parameter value in the “Capsule half Height” section, since “pelvis” to “head” are above the ground, but the legs are buried in the ground.

        thanks again 🙂

  4. Hey!

    First, a phenomenal job with this tutorial.
    (I’m running 4.14 on my project and only had to do some minor adjustments. as I believe some things just look a bit different). But everything was clear enough that it wasn’t that hard to figure out.

    So thank you!

    But, I do have a few glitchy issues. I’m not sure if the capsule actually moves. The leg get’s moved into the mesh instead of colliding. So if it moves it really messes up collision.

    Sometimes the feet will bend oddly. I think this might just be because the surface has tiny normal surfaces that it tries to align too. not to big of an. issue visually.

    The biggest issue is that most of the time the feet are a little bit beneath the ground. Especially up and down slopes.

    Any help appreciated!
    And again.. thanks!

    1. Thank you 🙂

      Well, for your first issue it’s because this system use a line trace, it will line up from the heel to the ground.

      For the second issue, try to move your mesh a little bit upper.

  5. Hello! First of all, thank you so much for this tutorial. I reproduced it step by step, however I get a strange legs behavior, it always offsets character legs too much no matter what values I change, but only when tracing against some sort of surface, which is not a flat plane. I have a strong feeling that offset is not being adjusted. Changing “IkAdjustOffset” does not helps to resolve the problem, it only makes character being moved lower then it should be while standing still. Please take a look at screenshot I made, I would appreciate any help with this issue. http://imgur.com/a/eEhNB
    (UE version 4.15)

    1. Thank you Raindance.
      I think there is somethings wrong with your trace function. Be sure to follow the tutorial step by step. I’ve tested it on 4.15 making a new project and I have no issue.

      1. Hello again!
        I am sorry to bother you with questions, but I still can’t figure out how to fix problems with this IK solution. I’ve spend pretty long time trying to figure out what is wrong with setup I made, and I can asssure you it is absolutely identical to one in tutorial.
        What I figured out: collision capsule gets on a way of IK, which causes capsule to raise character when colliding with surface. The only possible soultion here is to move capsule with character pelvis +amount of offset from ground to current calculated Z amount.
        There is, hovewer, a second problem, which I have no idea how to fix.
        After every small movement on non-flat surface, be it slope or ladder, character get’s pushed just a little bit from side to side. Turns out, collision capsule is being moved on top on currently tracing line, and it also makes character being moved, because capsule is a scene root. Is there any way to prevent capsule from moving from side to side and make it stay in center?
        Please take a look at picture I made.
        http://imgur.com/a/C29Mx
        And I must say this kind of IK solution works perfect with any surface which does not collides with capsule.

  6. Hey Alessandro! Great tutorial! Also, i was hoping i could get some help! I’m using the Longmire’s Advanced Locomotion package from the marketplace with your IK setup. It works as designed other than the fact that the pitch and roll angle on the ankle joints continuously rotate as i move the camera around the character. Do you have any idea what this could be and how i could solve this?

  7. Hi, great tutorial, I’m having a problem in the anim graph where it says “Entry node ‘Default’ is not connected to state. I couldn’t find anything in the tutorial for what goes in the default state machine.

  8. Hay, amazing tutorial my friend i really appreciate your effort, i have followed all your steps and set the variable values correctly, i have tried to use the debug to follow the execution pins and every blueprint is working, but the character just doesn’t seem to have IK foot at all, Will you please help me.

  9. Hello, I’ve completed your tutorial and figured almost everything out execpt for the Get Turn node in the IK Graph. I don’t know if it’s a function like IsMoving is, i’ve looked through this page multiple times and i’ve searched almost everywhere. I’m sure it’s something small that i’m overlooking but if you could help me out that would be amazing. Thanks.

  10. Hey,
    I managed to make it work/kinda, however, I have a problem with collision
    Photo here:
    https://prnt.sc/iwtgqu
    https://prnt.sc/iwtgvz

    Essentially the character skeleton doesn’t get updated tried to find the problem but I didn’t manage to figure it out, I know its kinda an old thread but help would be appreciated thx! Cheers!

  11. Hiya, I’d like to just say thanks for this tutorial first of all. It is pretty clear for the most part, but I have no idea what I’m looking at in the “IKUpdate” bit of the tutorial. I understand that you had to zoom out, but I cannot see the variables properly. The floats and the names, which I imagine are the socket names – I literally have no idea what to put there? And I’m pretty confused about how everybody else knows what to put except me? Am I blind hahahapleasehelphahaha.

  12. Okay I’ve realised that you go through it later on, I just didn’t read the rest. Thanks again! Sorry about that, cheers.

  13. Hi, I am very new to ue4 and animation, so I don;t understand this part “LeftJointLoc Set to a value that look good in anim preview”

    What does that mean?

    Thanks

  14. Hello I’ve been trying to learn to setup Ik on a character and found your tutorial. You set a lot of things up in ways I haven’t seen before so it was hard but I learned a lot getting through it. I’m almost done,but kinda stuck on the last portion where you put together the “IK GRAPH” Where are you building that? is that In character blueprints? level blueprints? The first node says Inputs. The only place I’ve seen that node is when making a macro, but in there, the node doesn’t have an executable pin like I see in your image.

    thanks

  15. This is awesome! One question: This works perfectly on sloped surfaces, but it seems to jitter on staircases. Any idea why that would be?

  16. Hey! I would like to give you credits for your work on my project, any name/socialmedia you want to have on it?

  17. I’m super late to this but I have a couple of questions:
    1) is IK Graph a Macro?
    2) If so how are there custom events within a macro?
    3) When are you calling IK Graph?
    If you can shed some light on this that would be wonderful!
    I’ve re-read this post many times and got everything else hooked up but I just can’t seem to find out how you did the last step.

Leave a Reply to Hans Hauser

Your email address will not be published. Required fields are marked *