# How to Add Foot Placement IK in Unreal Engine 5 (Complete Guide) - Foot IK tutorial

**Channel:** Samar Dev
**Source:** https://www.youtube.com/watch?v=-Rl6ecndCHA
**Transcript page:** https://www.withtranscript.ai/video/-Rl6ecndCHA

## Chapters

- 0:00 — Introduction and Virtual Bones Setup
- 3:08 — Creating Control Rig and Foot Trace Function
- 8:09 — Foot Trace Variables and Smooth Interpolation
- 12:22 — Lowest Foot Offset and Full Body IK
- 17:40 — Animation Blueprint Integration and Testing

## Transcript

**[0:00]:** So, hi guys. Welcome back. And if you've ever tried to walk your character up a ramp or uneven surfaces in Unreal Engine, you may have probably seen the same issue that I did. The character feet slide across the surface or they float in the air. And the reason is very simple. The character feet don't know where the ground is. And here is the thing. There isn't any proper tutorial out there. And even if there is any, they are old and outdated. So, I built one from scratch as you can see in the video right now. And you can have your character walk across the ramp or uneven surfaces without floating in the air. And I will also walk you through how to set up a full control rig and explain everything along the way. So, even if you have never touched control rig before, you are in the right place.

**[0:57]:** So, without wasting any time, let's get a straight into it. So, the first thing that we need to do is add some virtual bones to our character's skeleton. Find your character's skeleton mesh and open it. And the first thing that you need to check is if your character's skeleton has root bone or not. If your character doesn't have a root bone, especially if you have imported the character from Mixamo, you need to add one. Otherwise, it is going to create a lots of problem later on for things like root motion in your animation or for animation where the character actually needs to move from the root, you will need to have root bones. So, what you can do is you can download something like Mixamo Converter or add the bone yourself in Blender or Maya. And here you can see the root bone has to be on the ground like that.

**[1:52]:** And then the the skeletal hierarchy needs to start from the root bones. So, once you have the root bone, we need to add some virtual bones to our character. And you might be wondering why we are creating these virtual bones when we have the actual foot bones. Well, we could use the actual foot bones, but I prefer to create separate virtual bones for our IK setup. What this does is this gives us dedicated bones that we can use as reference for our foot placement without changing or depending directly on the character's original foot bones. So, we're basically creating our own IK reference point for the left foot, right foot, and the root. This will make things a lot easier when we start building the actual foot IK system. So, right click on your root and click on add virtual bones and select the root itself.

**[2:46]:** And now you will see this FV root. Now, right click on that virtual bones for root and search for foot. So, we need to add for left foot and we need to add for the right foot as well. Right foot. Now you can see we've got these three virtual bones over here. And that's what we want.

**[3:08]:** So, the next thing that we need to do is we need to create a control rig for our character. So, I'm going to go to my character folder and create a control rig over here. So, go to the animation, control rig, and create a control rig. And I'm going to select the control rig and just name it CR there or something like that. So, now just double click and open it. And over here you can see this something called rig hierarchy. Just click on that and we need to import our skeletal mesh over here. So, just click on okay and you can see our skeletal mesh along with the virtual that we just created. So, now the first thing that we need to do is we need to do a sphere trace from both of our character feet, from here and from here. And you might be asking why.

**[4:05]:** Well, the foot trace will detect where the actual ground is. If you see over here, it will detect where the actual ground is. And it will adjust itself. And you might be asking what is a sphere trace? Well, it's basically like sending a invisible ball from one point to another point, from this point to the ground itself. If that ball hits something along the way, the trace gives us information about what it hit and where it hit it. So, in our case, we are going to send this is sphere down from the character foot. And if it hits the ground, we know where the ground is and we can use that information to move the foot into the correct positions. So, once you know what a sphere trace is, let's actually create one. So, for that one, I'm going to create a new function called foot trace.

**[5:02]:** And search for something called get transform. And here you can see this item. You can drag it into the entry. And I'm going to rename it called IK foot bone. And now, we need to do the actual trace. So, search for a sphere trace by channel. And pass this hit location as an output because this is where the actual ground will be. I'm going to rename this to hit point. Okay. Onto our sphere trace by channel, let's change this radius to three, which should be okay. We've got this is start and end? So, what should be the start? The start should be the character foot itself. The virtual bone that we just created. So, I'm going to use that translation over here. And also, what I want to do is I want to add some point on the Z axis. So, it not only look for the surfaces over here, it will look for surfaces if there are any if there is any surfaces a bit above the foot as well.

**[6:19]:** So, for that one, I'm going to add a node called add. And then, onto the A, I'm going to use the X just as it is. I'm going to use the Z as it is. And onto the Y, I'm going to add something like five unit.

**[6:44]:** So, instead of just starting the trace from the center of the foot, it will start so a bit on the side. And after that, as I said before, I'm going to add around 50 units on the Z axis. So, it not only detects on the foot level, it will try to detect something at the top as well. So, this will be the start point. Now, what is the end point? For the end point, I'm going to add another node called subtract. And onto the A, it will be the same value like before.

**[7:23]:** And then onto the B, I'm going to subtract 100 on Z axis. Which means it will try to detect what's below the foot as well. Now, after this one, we are basically done with this function. So, come to this event graph. And onto the event graph, you can see something called forward solve. And you might be wondering what is this? It's basically like even tick. It runs every frame, but it doesn't have that delta float inputs. So, what we can do over here is now we can run the foot trace over here. But, before running this function, let's actually add a variable called can do foot trace.

**[8:09]:** And you might be wondering why are we adding this foot trace variable? Because there might be a condition in future that we might not want to do foot trace at that time. For example, if you are jumping, we don't want to do the foot trace. Or if you're running, we don't want to do the foot trace. So, I'm going to add a branch over here. And then, this will be the condition. And onto the true, we want to do the foot trace. Yes. And onto the IK bone, just select this as a bone. And under the name, I'm going to use that virtual bone that we just created. So, let's do this for the left foot first. And onto the hit point, we just want the Z hit point. We don't really care about X or Y. Because we just want to know how much to bring the character up or down, right?

**[9:03]:** From the Z axis, just click on promote to variable. And I'm going to rename this variable something like Z offset L target.

**[9:20]:** And we need to do the same thing for the right foot as well. I'm just going to duplicate that function. And change this to right foot. And I'm going to create another variable over here. And I'm going to rename it to R. Now, just drag this variable over here and click on set. So, this will be our right foot offset. So, here we've got our foot trace working fine and we've got our offset as well. So, I'm going to comment this out saying something like a step one. Foot trace to detect the floor.

**[10:07]:** Detect the ground. And now, since we've got this raw offset value, we don't really want to pass this raw offset value directly into our character because it will make the character snap. So, what we want to do is we want to use something called interpolation. Also, rather than just continuing the graph from here, which will make it very messy and very long, I will add something called sequence. So, what this does is the sequence will execute whatever on the A, it will execute that first and then it will execute whatever on the B. And then if you keep on adding pins, it will execute following on the C and D like that. So, now onto the B, what I want to do is I want to do interp over here. So, just get the left target uh for now and search for all find her.

**[11:08]:** And then uh interp result, yes, we want this to work. So, just click on that. And then for the speed, I'm going to make it 15. And I'm going to save this as a variable as well. And I'm going to rename it to Z offset L. And just connect it over here.

**[11:38]:** And then I'm going to do the same thing for right.

**[11:45]:** Alpha interp

**[11:50]:** And I'm going to save this as a variable as well. This will be Z offset R.

**[12:01]:** Same thing. Just take this one and speed to 15 and 15. So, I'm going to comment this out saying step two uh adding smoothness.

**[12:22]:** So, now once you've got this uh interp offset for both left and right, we need to now check which one is the lowest. So, over here we need to check for example, if our character is over here, we need to check which uh trace will give us the lowest value. This foot or this foot? And obviously in this case, this foot will give us the lowest value and we need to use this value to move our character down. Let me pause the game. So, for that, what we can do is we can get this Z offset L and then search for a node called less. And then the B will be our And then, so what this node does is if our offset L is less, this will return true. If that is false, if R is bigger, this will return false. And we have a node called if in this control rig.

**[13:23]:** So, what this if does is So, this is like a branch, but it's a bit different. So, if our L is greater or sorry, is less than R, this will return true. So, that means on the true, we need to pass Z offset L. And if this is a smaller than L, it will return false. So, we need to pass this offset R. And this new result can be a new variable called I'm going to call Z offset hips or pelvis, whatever you want to call. That's it. So, I'm going to comment this out as well. I'm going to call it step three.

**[14:16]:** There we go. Now, what we need to do is I'm going to add one more pin over here. We need to add something called modify transform. So, onto the seat, I'm going to add something like modify transform.

**[14:33]:** And you might be wondering what is modify transform. Since we know how much each foot needs to move, we need to actually apply those offsets to our IK foot bones. And that's why we are using this modify transform. So, for this one, let's do it for the left bone first. And then, onto the transform translation, I'm going to use this Z offset L. And also, we need to use the mode to additive global, which means just add onto the existing value. Whatever this offset value is, add onto the existing current location Z value. That's it. So, now we need to do the same thing for right bone as well. So I'm just going to copy the node and just change this to change the item to right foot. And then onto the translation, I'm going to pass this set offset R.

**[15:44]:** Now, let's do the same for our hips bone as well. Just going to duplicate it. And now for the hips bone, I'm going to actually use the proper hips bone. And you might be wondering why are we actually using the hips bone rather than the virtual bones over here. The reason is we're using the actual hip bones here because we are actually moving the character pelvis. We are not using the hips as an IK target anymore. We just want to move the actual pelvis up or down based on which foot is lower. And that value is over here, set offset pelvis. This will give us whichever foot is lower. And that's it. And now after this one, we can actually add the full body IK. And then for the full body IK root, I'm going to use the hips as we are bringing the hips up or down.

**[16:42]:** And then for the effector, I'm going to add two of the effectors. The first one will be our left foot over here. I'm going to add the actual foot over here and then the right foot over here. And also for the transform I'm going to get the transform like before. And I'm going to get the foot left and pass it to the transform. That is done. And for the right transform, I'm going to duplicate that and get the right foot virtual bones transform. And then also onto the setting, we need to change this from pre-pull to pin to input. And that's basically the main setup for our foot IK.

**[17:40]:** Now, we need to actually apply this one. So, for that one, we need to find our animation blueprint. I've got it over here. And then come to the anim graph like that. And you may have something like this. You may not have this cached pose. You may have something like this one over here. Or you may not even have this default slot. So, what you need to do is first thing, you need to save this as a cached pose. I'm going to call it locomotion. Why? Because now we can use the same machine state machine again and again by just searching for locomotion cached pose. That's it. And that is what we are going to use right now. So, right after that, we need to search for a node called control rig. And then onto the detail section, onto this control rig assets, we need to search for CR_Player, the one that we just created.

**[18:38]:** And if you have remember that we've used this can do foot trace um boolean over here, right? So, we need to use this one over here. To do that, this we have to make this instant editable. And now, if you click on that, you can see our input pin over here. Just click on that. So, now we have got that over here. Now, we can add those gates over here. First, let's try this by just making it true so that control rig will work by default and see how does this one looks.

**[19:20]:** So, it is working right now. But, what if we jump? You can see the problem over here. It's not as a smooth as it is without the control rig. So, instead of just making it true, let's add that get that is you might have something like is falling or it's jumping or anything like that on your setup. I have this called is falling. And I want to use this when my character is not falling. That's it. Also, I want to do one more thing and that is I don't want this to run when my character is running. Like I just want this control rig when my character is idling. So, for that one, I can search for something called blend poses by bool.

**[20:16]:** Which means if this bool is true, this true pose will work, the one with the control rig. And if this is false, I just want to use the normal locomotion without the control rig, without everything over here. I just want to use this one. And this active value, this condition will be my ground speed is less than or equal to zero. Which means if my ground value is zero, I want this control rig to work. If it is not zero and if I'm actually moving, I want just I want to use just this locomotion. So, let's have a look now. So, onto my character, as you can see, the foot is actually working fine. It's not floating in the air like before. And there we go. So, this is it for this video. I hope you have learned something about Control Rig from this video, and if you do, make sure to leave a like and subscribe my channel, and I will see you in the next one.

**[21:19]:** Thank you so much.
