Control Rig #2: Forward Kinematics | Unreal Engine Tutorial

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
[Music] all right everybody welcome back to another Asad Dev control rig series video topic today we're going to be talking about forward kinematics or FK controls my name's Kevin we have a bunch to cover we're kind trying to keep these succinct so we're going to be hopping right in but if you haven't realized it yet these this entire series is also going to end up being a small 101 course and how to rig and create your own characters just as far as character setup goes so before we get started with setting up our own FK controls we're going to be talking about FK controls a little bit more about controls control placement as well as the forward solve but before we do that I think it's probably best to explain to you all the difference between forward kinematics FK and inverse kinamax or ik that way you have a solid understanding of what that is foundationally as we start to build that out to do that let's hop into unreal and take a look at some examples so here we are in Unreal Engine we have two mannequin characters these are both uh the default control rigs that come with the third person setup that is now part of Unreal Engine 5 and one of these characters is set up for FK or for kinematics and one is set up for ik inverse kinematics now we're talking about forward kinematics today the math version of what forward kinematics is is basically all of the angles of all the controls cast down to determine the Final End effector position what does that mean it means that based on how you rotate your upper leg your lower leg and your ankle the final foot position is determined by all those rotations now a better way to think about that in not math speak is all of the changes you make have a cascading effect because of the parent child relation if I rotate the hip bone the knee bone goes with it then if I rotate the knee bone the ankle bone and so on and so forth so let's take a look at that in practice if we take our hipbone this is our FK setup you can tell because the way these characters are set up we have our um basically our Circle controls that Define FK if I rotate my hip you'll notice that the entire leg moves everything is affected so if I need to rotate my knee now just my foot and it basically is going to do this based on the parent child relationship now let's contrast that against what an inverse kinematic setup is the inverse kinematic setup is exactly the opposite it takes the final position of the end joint or affector in this case our foot and it back calculates all of the angles of the joints to determine what they should be based on the parents position so the easiest way to explain this or show this is when I grab my hip control if I move it you'll notice that my character's knees Bend and you'll also notice my character's elbows Bend this rig on the left is set up to use inverse kinematics for the feet and the arms and what is happening is as I move the body the inverse kinematic solver it's called is calculating what those knee positions should be to back calculate based on where the body position is contrast that with the forward kinx version that I have here on the right if I move this you'll notice that my character maintains its pose the feet go through the floor and everything is affected so we're going to be talking about forward kinematics today why or what are some quick advantages just so you know for your own edification forward kinematics uh from an animation perspective uh largely depending on who you talk to uh forward KX is a lot easier to work straight ahead it's a animation workflow uh it also is a lot easier to get more depending again who you talk to it's a lot easier to get more realistic looking motion because that is the way your body works you don't calculate your elbow position based off of where your hand is in in some cases like so you can think you can dance people who can pop and do all those kind of crazy things yes you'll see that but generally speaking when when I go to move my arm it starts at the shoulder moves down in the elbow and then results in the wrist it's kind of like a forward motion same thing with their spine I don't rotate my chest than my hips that's just not the way it works I rotate from the hips all the way through my chest so generally speaking forward kinomax uh is a little easier for straight ahead it's a little easier to create natural motion it's also a lot easier to stay on character model what I mean by that is um basically when a character gets created if you are using just rotations it's a whole lot easier not to over stretch or over squash your character whereas with an ik solution when you're translating things you can overstretch your character and you kind of break the silhouette if you will but let's not get too far into that just understand there's a difference today we're talking about Ford kinematics so with that let's delete these guys we'll get rid of our sequencer our controls yep we can get rid of all of this and we're going to go create our own control break from scratch now if you have watched the dragon FK control setup video a lot of this is going to be repetition so feel free to skip ahead to ik there are a couple uh extra little tips that I've thrown in there I will try to bookmark those with chapter Selections in the basically in the chapter selection sections down below so once again again getting started we're going to go to our meshes we're going to create a control rig for we're going to use Manny simple and we just simply right click we choose create control rig and we're going to name this control rig FK now we should probably name this Manny simple so we know which character it's for and many simple FK because we're only going to be working with FK today so when we double click on this asset we are back to our now familiar control rig interface and we have a lot more that we're working with we're no longer working with just a single joint that we created so again we have our rig hierarchy we have our forward solve and we don't even have construction or anything in here so let's talk about creating our first FK controls and we're going to do that using the leg so I'm going to collapse down a couple things here just to so we don't we're not overwhelmed visually now if you recall from our last video in order to create a control there were two ways we could just right click and create a new control I don't want to do that because I want to cheat and use the fact that if I right click on the left thigh and choose new add controls for selected it will automatically name my name my thigh control to match the bone name with an underbar control in it and the naming is going to become important later because we are by the time we're done today we are going to have an FK control rig that we can copy paste and use on any character no matter how many controls they have so that's the goal okay and as before we're going to go ahead and I'm going to change my color to be a nice pretty blue because this is the character's left side uh although that did not seem to register so let's try that again there we go click okay now I can't see my control it's in there so let's just make it a little bit bigger and rotate it 90° and we're also going to go ahead and make this a thin circle little bit bigger there we go so now we can see our hip control it's nice and we're going to go ahead and create our knee control and we're going to be doing this the same EX way I'm going which in this case is actually called the calf with Manny so we're going to right click on here I'm going to choose new add controls for selected and that's going to create the calf control okay so we did all that we're going to color it we're going to scale it we're going to do all those things great that's awesome but there's a faster way to do this we can do them one at a time uh and we're going to get into the faster way here in a second but I want to show you some of the uh Clarity of understanding of the importance of hierarchy here in a minute so let's do the same thing with our calf control we're going to rotate this 90° we'll lock our scale scale it up let's change our uh shape to control then okay so we have our controls we created these the goal is to be able to use these as forward kamatics which is literally just taking the current control position and setting the bone position based on the control position and if you recall this is all a little bit of a recap from the last video If all we do is take our well we can get both of them this is our calf control and we take our thigh control and we get these okay we have each of those we are going to be setting our thigh left Escape thigh left let's set the bone okay and we're going to set this bone position to be our thigh control position because wherever the thigh control is whatever it's rotating to that's how we want to drive our setup and this is technically forward kinematics because based on the rotations Etc so we're going to do the same thing with our calf now this is actually going to uh create a problem uh I don't want to get bone I ACD chose the wrong thing here let's drag our calf in here and set bone and now I'm not going to connect it at first because I want to show you if what we do at this point because we've set our our solve and we're only connecting our thigh when I rotate the thigh you'll notice my leg moves but I want you to notice that as the leg moves the knee does not that is because currently there is no defined relationship between the thigh and the calf so there's nothing to tell this to move with the thigh bone we need to establish a hierarchy and that is going to be even more evident because when we connect our thigh bone or I'm sorry our calf bone to our to our control and we basically Drive our calf position and rotation from our calf control now if we pick our calf control and we rotate everything's happy it works but if we pick our thigh bone and we rotate you'll notice that we're breaking our character's leg and this is because we need to think about we need to understand that hierarchy matters even in our control setups so if we're using a forward kinematic setup an FK setup what we need is we need to establish that relationship that the calf bone is parented to the thigh bone and the ankle bone is parented to the calf bone and so on so by default what I could do here is I can just take this left control the calf control and drag it onto the thigh control that will now create a parent child relationship now wherever I move if we compile this wherever I move my thigh control my calf control is going to go with it and now I can pose my my knee joints okay that's really cool however and actually that it is that simple that is a forward kinematic setup it's B basically just straight ahead rotations based on hierarchy and the and the parent child relationship driving our in joint positions all right now that's all well and good however let's make this a little bit uh larger oh and actually let's go ahead and increase our our size here so you all can see this a little bit better make that a little bit better okay so now we're going to redo this again but we're going to do it faster uh and we're going to basically iterate on that a couple of times so what I'm going to do is I'm actually going to delete these two controls both of them I'm going to get all kinds of warnings that these controls don't exist and you'll notice that my character's leg has melted as a result of that that's because I deleted those while everything was still connected if I disconnect it my legs snaps back to normal now a faster way to create those controls and the hierarchy this was a tip from hot sauce we've gotten so many cool tips from all of our community members in this but if we just basically click our left and uh our thigh calf and foot all at the same time sure let's go ahead and pick the ball because it's that easy if we rightclick we can choose near uh new add controls for selected when we do that it is going to build the entire hierarchy for us so if we basically open up this drop down and just a quick tip if I want to see everything in the hierarchy if I shift click it will open it all up if I shift click again it will close it all up so shift click the little drop downs and they all show up so you can see here we have our thigh calf foot ball Etc all already parented all already named so I'm going to take oops I'm going to take all of these we will quickly change all of these to Blue by setting blue and then and we'll scale them we're also going to set all of these to Circle Thins and we'll scale them up and rotate them 90° and now all of a sudden we have all of our leg laid out and ready to go we've created our controls it's that fast so if we compile this and we reconnect in we should be back to having all of our controls movable so just like that very quickly we have our FK set up however we are now in A New Nightmare world where for each of these controls we're going to have to get the control name set the bone name get the control name set the bone name we don't want to do that let's just create one forward saw that will work for any and all FK Solutions as long as we use proper naming that's what we're going to do right now but before we do that I want to show you another quick tip that we we we got uh from another one of our members which was um ragna the blooded blood Edge I probably mispronounced that name but another cool tip what we can do is we can actually change and so for example if we pick all of these controls a we talked about how to edit these in our previous video using these shape transforms but what you can do is you can enter a mode where you can edit them actually in the viewport so for example right now I'm happy I scaled them all up together I'm pretty happy with my hip size but my knee size I'd like it to be a little bit smaller if I press control plus period you'll notice it goes into this um SCI is this magenta yeah it's kind of like a magenta hot pink mode where it's basically says it's currently manipulating the shap shape transform all right and now when I make these changes all of these changes if you look on the right you'll see that they are actually adjust justing the shape transform not the actual transform of this control shape which is cool and if I pick another one does the same thing so I can adjust these quickly to make them smaller down the chain because I don't want this giant thing on the character's ball and when I'm done I can control period again to get out of that so that was just another quick tip again why the community is awesome we get we get those kind of things so we're happy with the way these controls are set up what we're not happy with is the fact that in order to get an FK solve for each of these we have to go through and create a whole bunch of these nodes so we're going to get into a little bit of scripting here to help us create a forward solve that will work for all of our joints so here we go uh what we are going to do is we are going to use the fact that all of our controls are named the same in the sense that we're following the same convention the name of our thigh control is thigh underbar Bar L underbar control the name of our thigh bone is Thigh underbar l so it's just without the control so we're going to get all of our controls using some scripting so let's get all and we're going to choose controls so this is going to create a list of all of our controls for us and all we're going to do is for each of these we are going to get the name and we're going to replace and we're going to use a string replace and what we're going to replace is we're going to replace the underscore control I always say underbar don't get confused by that underbar control with nothing with none and what this does is this gets us the name of our control this gets us the name of the joint that it drives because all of our controls are named the name of the joint under bar control right and then what we're going to do is we are going to set our bone transform to be from the name okay and what are we going to set it to we are going to get the transform we're going to get the transform from the control and then we're going to use that transform from the control and we're going to set the transform of our actual joint or bone with me now when we connect this up assuming we got it all right uh we will have full control over our our FK control rig now and when we rotate each of these items you'll notice that our character has full control over our foot and everything that we want so we can pose it out if we compile it snaps back to zero now the great thing about this is now if I add new controls to this character they will all just work so let's do that let's take and let's add in spine controls for example let's take our our our 1 2 3 4 five spine controls I'm going to right click and I'm going to create a new uh I'm going to add controls for selected because remember I want to keep that hierarchy and while we're doing this I'm going to disconnect my forward solve just just so that it's disconnected I'm going to take all of my spine controls I am going to change the color to Yellow because remember we like that Center and we are going to change this to Circle thin and then we're going to rotate rotate the shape by 90° and then let's scale them up so we can see them you can see them starting to come through here in our viewport which is great and then because we have the ability to do that I could I could tweak these these so that they're a little bit um so they're just a little bit easier to set up I'm just going to press the control period and we'll kind of scale them a little bit so that it's a little bit more apparent that these follow the body a little bit and I'm actually I think I accidentally unlicked the DOT so make sure you have that hot pink setup here otherwise it will mess with your transforms okay so very quickly we have laid out our spine I do want to double check that I didn't accidentally put something into the transform when I was moving some of those it looks okay so let's switch out of our shape editing mode compile and when we C connect this up we've literally just added all of our spine controls our leg controls are still here and now when I select them they will work I can now rotate actually I need to pick them all let's see here here we go so very quickly we're able to add all the controls for our character now we're doing this because first off this is FK it's forward kinematics so our resulting position of our hands as a result of spine 1 2 3 4 5 all the way down the chain now how how drastic could we be with this how quickly could we set up our entire character now that we've leveraged the fact that we can quickly create these controls and the naming Convention as a result of it to set up our entire character for FK let's give it a shot let's see let's see how long it takes so somebody start a timer so here's what we're going to do we're going to take uh what we've just learned we're going to take all of these joints point I'm going to right click and I'm going to choose new add controls for selection now what that's going to do is that is going to create my default control hierarchy with everything I need in it so let's take our twist controls out we don't need those in any case and actually the right side I'm not even going to worry about right now because uh that is going to create a there's two things we could do we could mirror or we could just use uh what we have created so for now let's just do that so here we go we're taking out all the twist controls I'm not worried about being able to control those so our root our pellis spine controls necks and heads we want those to be yellow and we're going to make those Circle Thins and we are going to rotate those 90° and we're going to lock our scale and we're going to scale them up so we can see it okay and what we're going to do is we're going to reduce these a little bit for our necks and heads and in the case of the head what I'm going to do is control period move that up so it's a little bit higher control period out of that pretty good there let's take a look at our clavicles all the way down we're going to take all these on the left side these are going to be blue make those blue we're going to make these Circle fins we're going to rotate those 90° so everything's in place now I'm going to make a quick adjustment for the hands and the arms lock my scale scale them up a little bit so I can see them I'll go ahead and control period scale down there the hand a little bit same thing over here okay now let's take a look at the hand the left hand if we want to make these indcs and metacarpal a little bit easier to understand what I'd like to do is I'd like to make it clear which direction they're they're set up for so I'm going to lock I'm going to keep my scale unlocked I'm just going to make them thinner on one axis then I'm going to lock my scale and scale everything together so now they're a little bit more representative of actual fingers for example now we have we finished the left side that looks pretty good at least as far as the arms go the thighs and legs same thing let's go Blue cool Circle thin great uh same thing 90° on our rotations scale them up looks good we can do the same thing for the right side now actually let's let's not do the right side I want to show you some troubles that are going to happen when we go to do some mirroring so for now let's just delete the right side okay shift selecting all these and deleting them so I don't even have a right side and we have one red control which is our root control which we are going to change to be a hex then I'll make it yellow and we're going to go 90 uh actually we don't need to go 90° for this one let's scale it up though let's go five 10 that's good okay so very quickly we have laid out all the controls for our character probably add on another 30 seconds to a minute to redo the left side I'm sorry the right side manually because we have a basically properly using the naming convention we are set setting our FK controls this character is now fully posable and we can take this and we can copy and paste this code to any character it doesn't matter if the joints are the same name or not because we are using joint name underbar control as our convention this exact script this exact visual blueprint will work for any character so we can simply pick a joint create a control for it and this will work we will basically get an FK control for free that just works now now that we have set up our FK controls imagine we had gone through the manual process of doing that on the right side the problem is there really isn't and feel free to chime in if you believe otherwise but there is not a mirror shape only option there is a mirror controls option but not a mirror shape only the reason that might be important is if you've meticulously placed all of your control shapes on the left side especially for like your fingers you may not you may not want to have to go through and copy all those to the right side so you're thinking oh let's just mirror it however that's going to be fun so if we right click and we choose mirror okay and we take our mirror axis and our axess to flip to be let's try none we basically give it our search our search string which is our underbar L under bar right R so we're going to replace the underbar L with the bar R when we click okay it will mirror to the other side but you will notice that that is ugly so none is not the way to go and none of these that I have tried will get you exactly what you need so let's go X this time right click mirror this time we're going to go X same thing under Bar L epic if you're listening it' be great if it remembered these settings click okay all right that's a little better we do have a bit of a problem with our uh fingers our shoulders Etc the reason this is happening is because the transform offsets for the left side versus the right side are not the same so what we need to do is we either need to recreate all the right side controls or we can use the construction script to set the default position of our controls to be the default position for the initial position of our joint point that are part of our character rig so what we did here to set each bone to the position of the control we're just going to do the opposite but in the construction script so let's make one quick change let's take our entire right side and make it red click on okay and it looks like somehow I deleted my legs but that's okay for the purposes of the demo that's okay so right now you can see we have our shoulders flipped so here's what we're going to do we need a construction script so let's do construction here's our construction event and remember what we said the way this works is the construction runs first it gets everything set up and ready to go before you actually start the solving so this is an opportunity for us to create all of the default positions or any default values that that we want as part of our eventual control rigs so what we're going to do is we are going to do the exact same thing we are going to get all of our controls and for each one so I'm just copying and pasting here for each one we're going to do the same name name part substitute we're going to get uh the control we're going to replace actually let's just copy paste this will be faster we're going to replace the under bar control and this time we are going to do a check we're going to add one little check in here because what I want to know is I want to make sure the item exists because what if we actually it has to exist oh no no no we're going to do item exists because we want to make sure there's a bone is it might be possible to create a control that is improperly uh named for example so does this item exist that's our question and if it does we're going to uh Branch I click I held B and left click to get that to pop up so if our item exists then what we are going to do is we are going to set the transform of the control so to do that what we could do for example is just take this and drag it in here set control but we are going to override the item it's not going to be the root it is going to be the item here let me zoom out a little bit and make this small so you all can see this okay so remember this is our control let's take this add a reroot now a route node so we can get to it this is the name of our control and we're going to connect this into the name of our control okay so if this exists we are going to be setting the transform let me make some room here now we also need to get the transform of our joint so we can take our transform okay and we're going to get the transform of the joint of the bone and we are going to set the transform of the control to the Bone value and when we compile you'll notice that my right shoulder does not fix itself we need to check I believe all we need to do is check this initial box oh yeah we also need to get the initial from this one as well okay let's double check and make sure we have everything set up properly oh we need to set the type bone my fault okay so here we go true we should be able to connect this in now compile okay great so that should set our initial now you'll notice that when we do that so what's happening here is we're getting all of our controls and then if the control exists we're getting the initial position of the bone and we're set setting up the transform initial or offset position for the control and what that does is that gets it so that our rig is all set up and pretty to start with so our right side looks correct from the start and is going to be pretty forced to animate then once this setup finishes this construction event finishes what ends up happening is now when we're posing our character we're using the forward solve and the forward solve means that we can move our right side our left side we can do whatever we need to to kind of rotate our characters controls into place we can basically pose out our character and that wraps up a whirlwind tour of how to quickly set up not quite procedurally but quickly set up a whole series of Ford kinematic controls for any character we can now take this and copy and paste it into any character and for every control we make as long as we name it the name of the joint underbar control this exact same blueprint will work for any character which is awesome we also talked a little bit about the difference between forward kinematics and inverse kinematics it's important to understand as well as some of the animation preferences as to when they would use either one in general for inverse kinematics one thing to think about is if your character is contacting something like the ground a door whatever generally speaking animators will want an inverse kinematic control so that they don't have to basically animate frame by frame to maintain that contact so imagine a character was trying to open a door as the door open you would have to move the control every frame to match that that would be incredibly painful so by providing an inverse kinematic control for those cases animators are much happier and so will you be uh when you're creating your own animations and unre engine so keep an eye out our next video we're going to be probably talking about inverse kinematics as always thank you for being the best part of uh doing all of these videos our community is awesome we appreciate all feedback if you notice something you have tips ideas better ways of doing things feel uh feel free to throw those out I am not afraid to re-record a video from scratch and as always uh help us out spread the word about the channel uh patreon super scker super chat always always appreciated you can find those links down in the video description below and we will see you on the next video take it [Music] easy
Info
Channel: Ask A Dev
Views: 2,458
Rating: undefined out of 5
Keywords:
Id: ENl6FhVEiwM
Channel Id: undefined
Length: 35min 8sec (2108 seconds)
Published: Sat Feb 17 2024
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.