Control Rig #7: FK/IK Switch & Snap | Unreal Engine Tutorial

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
[Music] all right everybody welcome back to another animation uh Asad Dev I don't even know what I'm talking about anymore like I've done this intro so many times anyways welcome back to Asad Dev we are working and we are continuing our um control rig Journey uh specifically recently we've been talking about FK and ik for inverse kinematics and reverse foot and foot roll and we're it's about time to bring all that stuff together so we are actually going to be working with FK ik switching and giving ourselves the ability to choose whether or not we're going to animate in FK or ik mode and then we're going to take a look at real time FK ik snapping Depending on time which is going to blow the minds of Maya users and stuff like that because of the differences in the way in the graph works but let's not get ahead of ourselves and let's hop straight into unreal and take a look at what we're talking about where we are so here we are with our control rig uh let me actually save this as a new rig so let's save this as we're going to save this as our uh not our reverse foot roll we're going to call this FK snap just so we have it and let's just close this down and reopen it just to make sure we have the right one okay so where we left off was as I mentioned we have a reverse foot we have our ik controls and we have a bunch of FK controls which are for right now all of our arm and spine Etc joints now these work by default because of all the work we did in the forward kinematics video if you're not sure what I'm talking about there's a link around here somewhere click on that and basically these are controls that are being built on the Fly procedurally which is a lot of fun now in order to properly demonstrate and talk about FK ik snapping we do need some FK controls for our legs so let's go ahead and grab those if we collapse our spine we're going to be working with the left leg today going to right click I'm choosing new add controls for selected that's going to create a bunch of controls for us we're going to do the exact same thing we've been doing uh so far we're just going to take all of these we'll go ahead and change these to Circle thicks and we'll rotate them 90° and then we'll do some scaling so they're easily selectable same thing with uh and then what I do want to do is for the ball I'm going to bring this down in size a little bit so that it's not Giant and then for my my hip because sometimes it's difficult to grab this I'm actually going to offset the shape in X just to make it a little bit easier to grab so it's not stuck right up against the body control so it's a little bit easier to see okay so now we have a series of FK controls these are our thighs our our thigh through our ball I'm going to parent these in appropriately and where I'm going to parent these is I'm going to parent these actually a lot of this stuff needs to be parented in but let's just parent this die control to the pis we'll go like that for now okay now by default let's see if this works if we grab our leg you'll notice that we can move our controls and this is where we get into why we need FK ik switches and snapping okay right now we have FK controls that we could we want to be able to control our leg with you can see as I rotate them they are moving however the leg's not but if we move our ik controls our leg works fine that is because we stole all of this is our construction script this is the construction script and if you recall from that FK setup video we basically went through and programmatically find all the controls in the rig and set them up that's cool the same thing as happening down here in our forward solve we find all the controls in the rig and we set the values but look what happens after we set the values for the FK controls we have a sequence and the next thing we do in our sequence is we come down here and we set all of our ik leg stuff so if we simply swap the order of these you'll notice that now my FK controls work I can now pose my leg using FK controls like so but my I controls no longer work so what we need is a way to give our animators the ability to choose which one they're going to use so what we are going to do is on our I think we're going to put this on a layout control we're going to give our animators a animation channel to work with so over here on the right let's add an animation Channel we are going going to call this I'm going to call this the left leg uh ik enable for example and I'm going to change this to be a Boolean now just like we did before when we were doing the animation Channel video if we select our left leg ik enable we set our initial condition to true that way because by default for the legs we probably want them to start in ik because they're they're usually in contact with the ground and now all we need to do is let's flip this back all we need to do is use this new channel to decide whether or not FK or ik is active so here's what we're going to do let's get this animation Channel and the channel that we're getting is our left leg and I also do want to make one other change in here just like we discovered in our animation Channels video I do want to rename the script name of this to be the proper name so it's there okay so all we need to do is if this is true we're going to do ik K and if it's false we're going to do FK for example that's the plan all right let's see if we can't set that up it's pretty simple we don't we're not going to use the sequence anymore and I don't want to confuse you but I am going to swap this because my FK is up here and I I don't I don't want to change my entire order right now so what I'm going to say is if this is not ik enabled then I want to do Ford kinematics so if it's not ik enable we're going to do forward kinematics and if it is I enable in other words if that's false we're going to do ik so literally just adding that that animation Channel gives us the ability to choose so here we are if we rotate our FK leg you'll notice it is not having any effect on our character that is because when we pick the layout control our ik is enabled if we uncheck this box you'll notice notice that my leg updates so I as an animator can now just uncheck and check this box to choose whether I want to animate in ik or FK pretty easy right that's it we're done no we're not it's not that easy um this is really great but this also illustrates a not a problem but a workflow I'm going to call it a workflow so as an animator when I'm working if I have taken the time to pose my leg first off there's there's a couple things about this right now I have both ik and FK visible all the time that that's fine that's a that's a minor thing we can just connect our enable to the visibility but I want to keep them visible for now so that you can see it because we are going to be working with trying to get these things to line up so as an animator as I'm working on a scene it is very common to want to align our FK controls to our ik controls or vice versa the reason for that is when we're animating let's say our our foot is in contact with the ground and then all of a sudden the character jumps in the air and does a flip it is a lot easier to animate a forward flip using an FK leg than an ik leg because as the character rotates the legs will just go with the character so what you might do is as you leave the ground switch to FK at that moment if the FK leg is over here in space and the ik leg is over here in space you'll get a snap you can get a pop in the frame so there's a lot of tooling that is done in various programs to do what is called fkik snapping and literally what it means is we want to take the FK leg and align it to where the ik leg is so for example if you're animating an ik when you start that launch position you want to start your FK leg from where the ik leg was so we're going to line our FK to our ik and then launch or vice versa you're in the air the character is doing their flip I know that looks like I'm calling myself crazy but it looks like the character is doing the flip just before they hit the ground you want to transition back to ik well you want to align your ik leg to where your FK controls are so you don't have big step changes in your curves and controls and all those kinds of things now I want to caveat that a little bit unreal is a new paradig for animating and there are things in Unreal Engine that potentially change the way we work I want to leave room for the fact that there are potentially alternative workflows and methods based on all the wild cool stuff that is in control rig so one of those we're going to be talking about right now generally speaking when you do FK ik snapping and a lot of other tools there is a a lot of other programs there is a separate tool that will help you do that because and this is going to blow my user mind because of the way control rig works and the graph works because it's event based what we can do is we can do live FK I snap without creating what is called a cycle in some of these old programs so literally what we're going to do right now is we are going to make it so that our FK leg is always aligned to the ik leg and I know this is very long-winded but it's important we're going to make it so our FK leg is aligned to our ik leg whenever we're in I K mode and vice versa so let's do that now before we do this I do want to make a couple changes because I want to be clear on which controls I'm working with so I am going to rename a couple of my controls I am going to choose for now until and until I have a better reason not to do this I'm going to uh intentionally call my controls FK controls because now now that we're working in a world where we can have ik controls and FK controls controlling the same thing the the our procedural script to just basically align any control to whatever is happening no longer really works and we need to be a little bit more selective as our control rigs become a little more complicated so um I'm renaming all of my uh legs to be FK control and that is actually going to break all of my procedural setups so in order for the purpose of this demo I'm not going to fix everything I'm just going to make it so that our FK controls work again so I'm going to the search and replace we were doing where we were looking for underbar control we're going to change that to underbar FK control same thing here so now Al although I spelled that wrong okay now when we do that that should bring us back to life and I think if we switch this and we make sure we're in FK mode our leg still works FK so that that simple change fixed that we now have an FK and an ik leg okay and but now all of our upper arms and everything they no longer work because they're not called FK anymore so uh we could add a section to that but for time's sake I'm not going to worry about that right now but just be aware that that is a thing that we will have to fix as well okay so now we have our FK and we have our ik controls all we want to do is we want want to when we are in ik mode which is this second Branch down here right here what we are going to do is we are going to align our FK to our ik positions this is awesome so let's take a sequence okay and the first thing we're going to do in our sequence let's make some room here and also we're we're starting to get to a point where our graphs are getting kind of crazy so we're going to start building some fun functions as well because this is getting a little unwieldy all right so this effectively is we can even comment it this is going to be our ik leg and reverse foot roll for example okay oops all right that way we know what that is explicitly now what we want to do is we want to align our FK to our ik now I'm being very very deliberate about how I say that because depending on who you talk to it could get confusing I'm going to line my FK controls to where my ik controls are first so to do that we are going to use a lot of the same procedural logic that we were doing before and what we're going to do I am going to take and this time rather than just taking all the controls I going to take all of the leg controls specifically I'm going to rightclick and I am going to I'm blinking on where it is I need I want to make an array from selected hold on new control naming mirror space switching where did it go I lost it ah there you go just drag it in create create an item array from selected so that is a quick cheat for me to create an item array that is basically all of my left leg FK controls so this is going to be the array that I'm going to use to drive my snapping now and we are basically going to reuse all of this okay so let's copy and paste this down here except instead of doing all the controls we're going to do just the FK controls and instead of yeah we're even going keep the global space bone okay so this is basically what this is going to do is this is going to find all of the bones for each of our FK controls and then it's going to align our FK controls to this so as part of our sequence and it's going to be wild when I connect this okay right now it hasn't happened yet because we're still in uh FK mode but when we switch to ik watch what happens oh oh oh one other mistake we're actually setting the bone this is not right we want to set our FK controls so hold on I I picked the wrong thing we're getting the bone let set the control uh name let's see here we're getting a list of controls we're substituting if the bone exists we're getting [Music] the rather than getting the item we need to get the bone of name and like so okay cool so now when we move this still not seeing this hold on a second what are we missing here warning th left is not valid that's because we are supposed to be using the control which is this one there we go okay important I copy I cut and pasted from the wrong one what's important about aligning our FK controls to our ik locations is we get a list of FK controls we find the bones we get the position of the bone and then we align that bone to uh then we align that control to our um to the current bone position which is being driven by the ik control so now look at the difference our FK controls are now following our ik control they are live snapping this is like mindblowing for Maya users okay because if you do this in Maya what you can get in without doing a lot of extra work uh you get what's called a cycle and you're you have you have a control setting a bone which is setting the control which is setting the original control which creates this Loop and your your rig goes nuts it's uh they're called Cycles but anyways the point is now wherever we position this in our scene we've got uh we've got the ability for our FK controls to follow our I now the cool thing is when we turn this off you'll notice that I just turn it off and you'll notice that my ik no longer controls it's no longer controlling my leg and my leg is already snapped in place to where it's supposed to be dude that's amazing we literally just set up live FK snapping now FK is easy this is where it starts to get tricky and I'm going to explain to you why that is so here we go let me explain to you what's happening no matter what you do with your ik control the FK controls can accommodate that position however the reason going the other way aligning our ik rig to where the FK controls are is difficult is because of two things one we have our reverse foot our reverse foot remember is uh the backwards hierarchy so the ankle position changes two there are limitations inside our ik solver where it is possible in FK to bend the knee outside of the plane of the solver it is a very difficult problem to find an appropriate knee position when you are limited by what the solver can do now there's all kinds of cool different solutions you can use NE offsets and we're not going to get into all that we're just going to set up a solution that will work but it's also it it's it's also like a it's a lot this is going to be a fun little Adventure now let me show you how much of a fun adventure it is this is the control rig that comes with the third person um the third person uh demo project okay and what I want to show you is much like the setups that we've been doing it has a lot of the same features in here however to just to illustrate how difficult this is if we pick the layout control and we take our left leg uh FK ik switch and we turn it off you'll notice that it switches to FK fine which remember I said it's pretty easy but when we go back look at what happens did you see how the foot moves we don't want that okay a lot of people would call that unstable or destructive but it illustrates how difficult the problem is because really smart people help set these rigs up that come as part of these projects and these things still exist now are we going to get a perfect solve no but we are going to I think we're going to get to a better solve than this because look what happens if I continually uncheck and recheck what's happening is my rig is in a never ending B battle with itself where it is literally going to spin out of control and never get back to it so we're going to do a whole lot of jumping through hoops to hopefully come up with a better solution than that with the caveat of it it one we're going to learn a lot period we're going to learn a lot two all of this stuff needs to be proven in production we need to spend some time animating with it we need to figure out where the holes are the gaps are Etc so take it with a grain of the salt think about this as a learning experience all right so so now let's start the adventure and to kind of explain some of the problem if we switch to FK which is where we're going to be going now what we want is we want when we're in FK mode we want the ik leg to align all right so first step let's get this ball control to be in the right place okay so to do that uh let's think about the best way to start here let's get all right let's do this uh okay so here we are this is our sequence because we are in ik mode okay great so let's make some room here let's move all of this down and make some room okay so here we are we know that we're in FK mode and we're going to pop in another sequence so that after we finish setting our FK controls what we're going to do is we're going to start our real time snapping and one thing we could do as an example is we could get the ball if we just come up here and we grab the ball this is not what we're ultimately going to do let's get the bone transform okay and then let's take our left ik foot which was down there let me collapse this so we can find what we're looking for here is our left foot let's set this and we're going to set this to [Music] be here step one and actually I don't want the ball what I want is I want the foot okay so now that is in place it's pretty good it's pretty good so if nothing at all that is at least a great step in the right direction even if you do that animation could probably work with it to a certain extent however we do have problems so our problems come in when we start doing things like where how do we get the pole Vector to be in the right place so let's deal with the pole Vector um and the way we're going to do that is we are going to reuse the stuff that we were doing up here to calculate the pole Vector so we're going to get the calf the Rotator we're going to add to that and then we're going to project out a vector from the knee and that's going to be where we're going to place our pole Vector for now okay so let's go ahead and uh paste that in here oops I missed a couple couple pieces of it or at least one piece of it okay so now this is going to set our translation and we are going to connect that into nope I missed okay so this is automatically setting our pole Vector I'm going to make this side a little bit bigger so hopefully we've got this so we're setting our we're setting our foot control and we're setting our pull Vector this is especially important when we start doing things like moving our knee off axis now this is a great example of a problem because generally speaking the ik solver can't bend the knee off like this so what's going to happen is when we uh snap this back you'll notice that the knee is going to pop however if we uncheck it and recheck it if we keep doing this we don't have a problem so it's just the first one it is the best we can do given the riggy knowledge we have so far and it is more stable than for example what we were seeing in the default one but we also have not tackled the challenge that is the reverse foot and that is where things start to go Bonkers so step one we actually have a pretty good FK ik snap it's pretty sweet but the trick this is where it gets nuts the trick in here is to deal with the reverse foot and what I mean by that specifically are we okay so we're currently FK so if we rotate our foot back put it in plane maybe something like this and then let's just say that we were going to do something like rotate onto the ball of our foot for example well the problem is with the current snapping it is not going to put any of this information on the reverse foot it is all going to get put onto you have to make a choice all right you have to make a choice you either need to put this onto the ik control and the ball offset that will work it is a simple solution however you probably have to have a conversation with your with team anom right figure out if team Anam is is whether they're more inclined to have the ball basically everything on the ball offset and the ik foot and then have to go back and pose it themselves using the reverse or vice versa but we're going to go ahead and do the tough one so there's a couple things that we need to change what we want is that when we rotate this ball we want the foot to go with it the reverse foot specifically so what we're going to do is we are going to take and rather than setting this control to the position of the foot what we are going to do is we are going to use a tool that we haven't talked about so it's a little unfair we're going to call Project a new parent all right and what we are going to project what this does let me get it set up so we're going to take we know we're working with the foot control not the fk1 we're going to be working with the left foot we going to take the left foot and what we're going to do is we are going to it's it's basically like the way the works is it it creates a temporary parenting if you will takes all of that transform information and converts it back to the space that you want it to be in so in this particular case we're going to use the ball left for both of these and we'll probably have to do a separate video on Project a parent but basically what this does is it says take the left foot control pretend that it is parented underneath the ball control ball joint then give me back the transform that it would have been if it was in that space But in the world of the foot control so it's kind of like a a really weird live parent constraint type thing but oh actually that's a really good idea let's go ahead and compile oh we compiled it all right let's go ahead and get back our pose but I wanted to compile and save real quick um okay so we have our POS let's get our pose back rotate this in place and then we had said that we were going to NOW Watch What Happens now when I rotate the ball watch what happens to this foot control so as we rotate this now you'll notice that it bends down this is a lot more in line with how the reverse foot control works because usually what you would do is this would be flat and you would raise onto the ball of your foot so this is perfect we're moving our foot control now we get to the fun part figuring out backward calculating what this ball control rotation the reverse ball control rotation needs to be in order to get it to align with the current position of where the ankle is so that's what I mean when I said things are kind of Bonkers because we are going to need to set up a couple of helper nodes to help us figure this out so let me let me show you what I'm talking about I'm going to take this enable I'm going to change my initial so that because we're going to be accidentally hitting compile a few times here and what we are going to do is we need a couple of nodes to help us out so here's what we're going to do imagine that you are standing at the ball of this excuse me super sensitive still all right imagine that you're standing at the ball of this foot and what we want to do is as the ball rotates we're going to counter animate that to do that we're going to use two null nodes and what we're going to do is we're going to take the child and we're going to constrain it back to the foot so what's going to happen is as the parent rotates the child is going to be counter animating to always point it where it originally started from and that is going to give us a series of rotational values that are exactly what we need to plug in to our eventually into our uh reverse foot control uh rotation local rotation space values so let's go ahead and do that now we're going to make some room here and what we need to do is let's take and let's move this off and let's just kind of make uh a couple of our nodes or our n first and get this going over here what we want to do is we want to put a null underneath the control POS okay so let's add a null here new n and I'm going to call this the left ball RV reverse FK ik at now I'm calling it The at because um I'm not totally settled on this naming convention do not take this as uh a naming convention advice but it's it in an old in an old life ATT stood for attach node I don't know what to call it right now because we've got a couple of these coming so uh I'm just going with that so this is our attach and the idea is this is the one that holds the position and rotation values because we're moving it in space and then the child underneath it is going to be all zeroed out so let's create a new null underneath this and this one we are going to name the exact same thing and this is going to be our offset all right now what I'm going to do so that you can visualize this uh it looks like our we lost our posst basically there's there's a couple ways to potentially solve this math we could use aim constraints we could use Arm constraints and there's there is a matrix math version of this however it hurts my brain and also because I'm I'm highly visual also I think the visual version of this will make more sense but if you are a matrix genius please help us out throw comments down below let us know what the easy Matrix version of this is but for now what we're going to do is I'm going to add a couple of visuals here so let's go new and in this case um we're going to put a control here and I am going to make this control a wedge do thick and actually let's do thin wedge thin and then let's make this parent wedge a lighter color and then the offset we're going to add another new control and we're going to do the same thing we're going to make this a wedge I'm not going to worry about naming them because we're just going to delete these These are literally just visuals to help you all see what's going on so we've got another wedge we'll keep that one red so they're different that way we can notice the rotation changes and then let's make the top one a little bit bigger so that there's some difference that way you can see so we have the two in here now what we want to do is let's get a pose let's get a pose back in here okay so what we want to happen is as this rotates we want the parent wedge to do exactly what it's doing it's following our FK control and what we want is we want the the smaller one the offset we want that to counter animate so to do that what we're going to do is we're going to take the child which is here this offset and we are going to constrain it back to the foot but maintain offset so let's go ahead and do that let's do a rotation constraint and what we're going to constrain is our null this offset null and what we're going to constrain it to is the bone for the left foot so let's go foot left now what you should see right away and you can see it already working what's happening now is you can see we have the current position based on of our FK foot control so sensitive and now when we rotate our ball you'll notice that the actual child the offset remains behind it's not really remaining behind what it is doing is it is it is actually maintaining the original rotation relative to the new parent and if you look at this let's go look at this what you'll notice is the values that are on this offset these are the rotation values that we can use to plug right into our reverse ball control so let's do that so all we're going to do is we are going to um let's see do I want to sequence here yeah I'm I'm actually you're going to see me cuz this this is going to jump cut uh there is a sequence in here but this is going to go away uh basically uh when we get into pull vectors here in a minute you'll understand why but for now what we're going to do is we are going to take the we're going to get this let's get this snull and we're going to take and this is going to be super important we're going to take the rotation from this reverse null and what we're going to do is we are going to plug that into to our left ball reverse control um and we're going to set rotation we want to make sure we're only setting rotation and what we need to do is we need to do it in this is important the right space if we plug this in something goes funky that is because well one we don't have anything plugged in so let's go ahead and plug in our to our rotation okay so that gets us back now what we also need to do because the values are going to be incorrect we don't want to do this in global space we want to do this in local space and the reason we want to do in local space is remember we are using Oiler offsets 20° 10° Etc to drive all of the underpinning of our reverse foot so with that simple change that should be it we are now counter animating and and basically on the fly backward calculating the rotation values that we need to use in order to place onto our reverse ball okay now let's see how we did here if we look at this as we would want this to be a pose for example when we switch back to ik how much does our foot move let's see how we did let's do it from we'll do it from this angle okay oh dude did you see that it didn't move it didn't move that's great right and now look at this now we're in ik and our ball roll is in the right place this is Bon like this is insane for people coming from May and other tools like the ability to do this is just it it breaks your brain and this is why I encourage anybody who's making this transition um bring your expertise bring your experience but also be open to potential new workflows and ideas and stuff like that so this is this is crazy cool um so anyways we have now set it up so that our ik snapping is working and the cool thing about it is let's see if we can test this ultimate test switching back and forth you'll notice our foot's not moving we don't have that constant looping degradation that's happening in the default mannequin body W which is cool so at this point we're solid like I mean we're there we we pretty much have let me think we have a lot of the pieces we need to have a pretty pretty cool default control setup for bipedal characters now there's there's some other things that are coming but we're getting there so real quick real quick recap what we've got now is we've got our FK controls being driven by the normal FK setup we have our ik controls that are being driven by the ik setup we have the ability to switch between them the only tricky parts are the work that we did with the aim constraints to backward calculate which way the uh reverse ball rotations need to be as well as the pole Vector those were the tricky Parts everything else was pretty simple so even if all you did was just take the first half of the video and just kept basic ik FK switching in with real time updates it's pretty awesome it's pretty awesome to be able to do that so with that we are actually going to call our FK switching uh switching tutorial WP as always thank you for checking out these videos thanks for being the best part of this our community is really the best part of doing all these videos uh I learned so much by helping answer your questions and stumbling through all of this stuff with you so thank you very much my name is Kevin as always anything you can do to help out the channel spread the word we have the patreon the super chats all those things don't forget to check out the live section A lot of our tutorials are in the live section because we try to do live unreal tutorials we have just I I jokingly say we have just the right amount of crazy to try to do this stuff live once a week but um as always thanks for checking out the videos and we will see you on the next one where we area going to be talking about spaces or maybe projected parents or something we'll come up with something cool all right take it easy y'all have a good [Music] one
Info
Channel: Ask A Dev
Views: 2,677
Rating: undefined out of 5
Keywords:
Id: MdjDkGNR6aM
Channel Id: undefined
Length: 42min 10sec (2530 seconds)
Published: Sat Mar 16 2024
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.