WEBVTT 99:59:59.999 --> 99:59:59.999 Today we will see what the deal is 99:59:59.999 --> 99:59:59.999 with all this IK stuff. 99:59:59.999 --> 99:59:59.999 We have done some work with IK before, 99:59:59.999 --> 99:59:59.999 but we will see all of it in practice. 99:59:59.999 --> 99:59:59.999 Let's start first with the foot IK, 99:59:59.999 --> 99:59:59.999 since we already did some hand IK and some look IK. 99:59:59.999 --> 99:59:59.999 The first thing I'm going to do is, 99:59:59.999 --> 99:59:59.999 I have a character over here. 99:59:59.999 --> 99:59:59.999 And I'm going to create a new script. 99:59:59.999 --> 99:59:59.999 So that we have an IK, to write an IK code set. 99:59:59.999 --> 99:59:59.999 So I'm going to name this "IK Handling." 99:59:59.999 --> 99:59:59.999 And I'm going to drop it into my character. 99:59:59.999 --> 99:59:59.999 Now for the time being, 99:59:59.999 --> 99:59:59.999 I don't want the scripts, 99:59:59.999 --> 99:59:59.999 but since I'm taking the avatar from beneath my character, 99:59:59.999 --> 99:59:59.999 I'm going to leave them right now and use them later. 99:59:59.999 --> 99:59:59.999 Now, one thing we need to do first, 99:59:59.999 --> 99:59:59.999 is our layers. Now I have these layers I don't really need right now. 99:59:59.999 --> 99:59:59.999 If we want to work on a layer, on a meta [?] layer with IK, 99:59:59.999 --> 99:59:59.999 we have to have this "IK Pass" [setting] ticked, 99:59:59.999 --> 99:59:59.999 and if you have an avatar mask on a layer that has no other mask, 99:59:59.999 --> 99:59:59.999 you also need to have, to [not be cooling?] the IK positions. OK. 99:59:59.999 --> 99:59:59.999 This needs to be up. 99:59:59.999 --> 99:59:59.999 Now for the base layer, 99:59:59.999 --> 99:59:59.999 the base layer automatically takes 99:59:59.999 --> 99:59:59.999 all the bones of the animation. 99:59:59.999 --> 99:59:59.999 Now we open up my IK handle script, 99:59:59.999 --> 99:59:59.999 First of all we need to know the animator. 99:59:59.999 --> 99:59:59.999 And we do it like this, as always. 99:59:59.999 --> 99:59:59.999 Let's start first with some targets. 99:59:59.999 --> 99:59:59.999 And I'm going to give it: 99:59:59.999 --> 99:59:59.999 "public Transform leftIKTarget;" 99:59:59.999 --> 99:59:59.999 "public Transform rightIKTarget;" 99:59:59.999 --> 99:59:59.999 And I also want to control the weight, 99:59:59.999 --> 99:59:59.999 so I'm going to also add a public float of... 99:59:59.999 --> 99:59:59.999 I'm going to name it "IKWeight" 99:59:59.999 --> 99:59:59.999 and I'm going to use the same float for both of the targets. 99:59:59.999 --> 99:59:59.999 Everything that has to do with IK must go inside on animator IK. 99:59:59.999 --> 99:59:59.999 The first thing we're going to do is set the IK position. 99:59:59.999 --> 99:59:59.999 Wait! Set the avatar IK goal, I'm going to say left foot, and the float value 99:59:59.999 --> 99:59:59.999 will be the IK weight we just created. 99:59:59.999 --> 99:59:59.999 I'm going to copy paste this, 99:59:59.999 --> 99:59:59.999 and I'm going to change this to 'right foot', 99:59:59.999 --> 99:59:59.999 and I'm going to copy paste all of them and instead of set IK position weight, 99:59:59.999 --> 99:59:59.999 I'm going to say set IK position. 99:59:59.999 --> 99:59:59.999 And the avatar IK goal will be the left foot, 99:59:59.999 --> 99:59:59.999 but over here we need to "pos" a vector 3, which in our case will be 99:59:59.999 --> 99:59:59.999 left IK target position, for now. 99:59:59.999 --> 99:59:59.999 So I'm going to copy paste ... and for the right foot, 99:59:59.999 --> 99:59:59.999 I'm going to add IK position. 99:59:59.999 --> 99:59:59.999 Let's initialize this to 1. 99:59:59.999 --> 99:59:59.999 And now back into here [?] 99:59:59.999 --> 99:59:59.999 I'm going to drop my IK target left, and IK target right. 99:59:59.999 --> 99:59:59.999 I'm going to hit play 99:59:59.999 --> 99:59:59.999 and I'm going to close the scripts for now, 99:59:59.999 --> 99:59:59.999 and you will see that... the left foot is trying to reach the IK target 99:59:59.999 --> 99:59:59.999 and as you see over here, it will go wherever we set it to go. 99:59:59.999 --> 99:59:59.999 Wherever we place our IK target. 99:59:59.999 --> 99:59:59.999 Now, when something like this happens, 99:59:59.999 --> 99:59:59.999 the knee is all wrong. 99:59:59.999 --> 99:59:59.999 So, how we can fix that? We can say, [inaudible] 99:59:59.999 --> 99:59:59.999 to new transforms, and the same as we did the avatar IK goals, 99:59:59.999 --> 99:59:59.999 we can say set IK hint position, weight, 99:59:59.999 --> 99:59:59.999 and set IK hint position. 99:59:59.999 --> 99:59:59.999 So. Now of course this gives us an error, 99:59:59.999 --> 99:59:59.999 because... we have the avatar IK goal. 99:59:59.999 --> 99:59:59.999 But a hint is not an IK goal, it is an avatar IK hint, 99:59:59.999 --> 99:59:59.999 and this doesn't have a left foot, but you can see it has a left elbow, left knee, 99:59:59.999 --> 99:59:59.999 right elbow, and right knee. 99:59:59.999 --> 99:59:59.999 So it's the same for hands and feet, it's actually the same. 99:59:59.999 --> 99:59:59.999 The same way you do it. 99:59:59.999 --> 99:59:59.999 So, we will use the left knee, we will copy-paste this over here, 99:59:59.999 --> 99:59:59.999 and over here, 99:59:59.999 --> 99:59:59.999 and we will say, this... we want this... right knee... 99:59:59.999 --> 99:59:59.999 and instead of the target position, we are going to use the hint positions. 99:59:59.999 --> 99:59:59.999 So, now we need to drop the hint positions, 99:59:59.999 --> 99:59:59.999 I have already made those, 99:59:59.999 --> 99:59:59.999 hint left, hint right, and now when we hit play, you will see that 99:59:59.999 --> 99:59:59.999 even if I move my legs over into a weird position, 99:59:59.999 --> 99:59:59.999 if I move the hints around, it will actually make the knee rotate 99:59:59.999 --> 99:59:59.999 to fix his position. 99:59:59.999 --> 99:59:59.999 So, with this you can fix a lot, [or] some, weird issues. OK. 99:59:59.999 --> 99:59:59.999 But, as you can see, wherever I leave my IK target, 99:59:59.999 --> 99:59:59.999 it will always have the same rotation. 99:59:59.999 --> 99:59:59.999 So. How I can fix the rotation is simply by doing, instead of anim [...] 99:59:59.999 --> 99:59:59.999 set IK position weight, I can do set IK rotation weight. 99:59:59.999 --> 99:59:59.999 And then set IK rotation. 99:59:59.999 --> 99:59:59.999 And of course, this won't take that position, but it will take the rotation. 99:59:59.999 --> 99:59:59.999 Let's go back over here. 99:59:59.999 --> 99:59:59.999 And now we will see that our IK target 99:59:59.999 --> 99:59:59.999 will always have the rotation of... 99:59:59.999 --> 99:59:59.999 The left foot will always have the rotation of the IK target. 99:59:59.999 --> 99:59:59.999 Now. This will have to automate all this stuff, 99:59:59.999 --> 99:59:59.999 and we want to automate it so that when we walk, 99:59:59.999 --> 99:59:59.999 we don't have to minorly move these around. 99:59:59.999 --> 99:59:59.999 So. Let's see how we can do that. 99:59:59.999 --> 99:59:59.999 First off, what we need to do is of course know when we don't want our animator 99:59:59.999 --> 99:59:59.999 to move, to use the IK. 99:59:59.999 --> 99:59:59.999 So. We know that if we are walking... On a walk, 99:59:59.999 --> 99:59:59.999 as you see, when he raises his feet from the ground, 99:59:59.999 --> 99:59:59.999 we don't want to use IK, we want to play the animation. 99:59:59.999 --> 99:59:59.999 But when he puts his feet down to the ground, 99:59:59.999 --> 99:59:59.999 then we want to enable the IK. 99:59:59.999 --> 99:59:59.999 And the way we do this, the same way we've already done this, 99:59:59.999 --> 99:59:59.999 is, we'll create two new floats inside our animator. 99:59:59.999 --> 99:59:59.999 I'm going to name one left foot and the other right foot. 99:59:59.999 --> 99:59:59.999 I've already made these. 99:59:59.999 --> 99:59:59.999 And then we will go into our animation, 99:59:59.999 --> 99:59:59.999 and we will go into 'curves', and ... let me see how we can, uh... 99:59:59.999 --> 99:59:59.999 And you will see that for the left foot, 99:59:59.999 --> 99:59:59.999 the value for the left foot for the curve 99:59:59.999 --> 99:59:59.999 is at 1 when we hit the ground. 99:59:59.999 --> 99:59:59.999 But as we are moving, and 99:59:59.999 --> 99:59:59.999 as he has to raise his feet off the ground, 99:59:59.999 --> 99:59:59.999 then the moment his foot is not touching the ground, 99:59:59.999 --> 99:59:59.999 the curve is at 0. And it rises again when he has to hit again. 99:59:59.999 --> 99:59:59.999 So we can even go a lot more. 99:59:59.999 --> 99:59:59.999 This is a little bit exaggerated 99:59:59.999 --> 99:59:59.999 so that you can see what we are doing. 99:59:59.999 --> 99:59:59.999 So I'm going to give him even more air 99:59:59.999 --> 99:59:59.999 before he's touching the ground, 99:59:59.999 --> 99:59:59.999 and I'm also going to add some more 0, 99:59:59.999 --> 99:59:59.999 I'm going to give him more time with the IK closed. 99:59:59.999 --> 99:59:59.999 And I'm going to make it only for the left foot, 99:59:59.999 --> 99:59:59.999 so that we can decide ... 99:59:59.999 --> 99:59:59.999 so that we can see the difference [between the left and right foot] 99:59:59.999 --> 99:59:59.999 between giving him more air on the curve to have the IK enabled, 99:59:59.999 --> 99:59:59.999 and the IK disabled. 99:59:59.999 --> 99:59:59.999 Now in my animations over here, I have only added - of course hit 'apply' - 99:59:59.999 --> 99:59:59.999 I have only added curves into my idle state, 99:59:59.999 --> 99:59:59.999 so in this idle state, this curve over here, if you open it, 99:59:59.999 --> 99:59:59.999 if you click the first one, 99:59:59.999 --> 99:59:59.999 we will make the curve for all of his length [legs?] have the 1 value. 99:59:59.999 --> 99:59:59.999 OK, so that means when we are idle, when we are in the idle state, 99:59:59.999 --> 99:59:59.999 our left foot and right foot [inaudible] will always be at 1, 99:59:59.999 --> 99:59:59.999 so that means we have enabled Foot IK. 99:59:59.999 --> 99:59:59.999 Keep in mind, how you set up the curves 99:59:59.999 --> 99:59:59.999 play a big role in how it's going to sole [?] the IK. 99:59:59.999 --> 99:59:59.999 OK, so let's back into our script 99:59:59.999 --> 99:59:59.999 and let's start doing some things. 99:59:59.999 --> 99:59:59.999 Now, I don't want to use any more the left IK and right IK targets. 99:59:59.999 --> 99:59:59.999 Since we're going to be deciding those positions, 99:59:59.999 --> 99:59:59.999 we always script. 99:59:59.999 --> 99:59:59.999 But I'm going to leave them since we're going to use them probably, 99:59:59.999 --> 99:59:59.999 even though the hand IK is pretty much the same for the hand, 99:59:59.999 --> 99:59:59.999 if I change here, left hand, for instance, 99:59:59.999 --> 99:59:59.999 Right foot... left... this will be the same, 99:59:59.999 --> 99:59:59.999 um, no, this we will change, and here say, left elbow 99:59:59.999 --> 99:59:59.999 and we can position.. we need to "pos" the left elbow, 99:59:59.999 --> 99:59:59.999 and the rotation of course... left hand, and left hand. 99:59:59.999 --> 99:59:59.999 So now, instead of moving the left foot, it will change the left hand 99:59:59.999 --> 99:59:59.999 and it will move him around. 99:59:59.999 --> 99:59:59.999 OK. It's pretty much the same with the legs. 99:59:59.999 --> 99:59:59.999 But we're going to see some more examples 99:59:59.999 --> 99:59:59.999 that will save us work, in our workflows. 99:59:59.999 --> 99:59:59.999 OK. It's pretty much the same. 99:59:59.999 --> 99:59:59.999 So, let's [sample?] our script. 99:59:59.999 --> 99:59:59.999 For now, I'm going to change this back to where it was. 99:59:59.999 --> 99:59:59.999 Not left hand, left foot. 99:59:59.999 --> 99:59:59.999 I'm going to delete the hints, or maybe just 'comment' them out. 99:59:59.999 --> 99:59:59.999 And I'm going to leave left foot... 99:59:59.999 --> 99:59:59.999 (correcting code from 'feet' to 'foot') He doesn't have a lot of feet, 99:59:59.999 --> 99:59:59.999 he only has one. 99:59:59.999 --> 99:59:59.999 I'm going to also add these back to the way it was. 99:59:59.999 --> 99:59:59.999 So we have all this... let me bring it over here. 99:59:59.999 --> 99:59:59.999 And now let's add some variables. 99:59:59.999 --> 99:59:59.999 We want a vector 3 for the left foot position, 99:59:59.999 --> 99:59:59.999 and we also want a vector 3 for the right foot position. 99:59:59.999 --> 99:59:59.999 We also need two Quaternions. 99:59:59.999 --> 99:59:59.999 One for the left foot rotation, 99:59:59.999 --> 99:59:59.999 and then a Quaternion for the right foot rotation. 99:59:59.999 --> 99:59:59.999 OK. So in our IK goals, let's [hands?] all this. 99:59:59.999 --> 99:59:59.999 We need two floats. The first one will be left foot weight, 99:59:59.999 --> 99:59:59.999 and the other will be right foot weight. 99:59:59.999 --> 99:59:59.999 So, let's change our weight for both the position and rotation, 99:59:59.999 --> 99:59:59.999 to the appropriate ones. 99:59:59.999 --> 99:59:59.999 So with these two separate floats, it will change the weights 99:59:59.999 --> 99:59:59.999 independently of one another. 99:59:59.999 --> 99:59:59.999 So now that we have our floats, we need to set them ... to connect them 99:59:59.999 --> 99:59:59.999 with the parameters from inside the animator, 99:59:59.999 --> 99:59:59.999 where we set our curve and all the stuff. 99:59:59.999 --> 99:59:59.999 And the way we do that is by simply using "anim.GetFloat", 99:59:59.999 --> 99:59:59.999 and we have the left foot, 99:59:59.999 --> 99:59:59.999 and for the right foot weight, we want to take ... the right foot. 99:59:59.999 --> 99:59:59.999 OK. So this opens up - manipulates the weight, with how the animator works, and 99:59:59.999 --> 99:59:59.999 what animation plays, and what group we have 99:59:59.999 --> 99:59:59.999 on the animation we're currently playing. 99:59:59.999 --> 99:59:59.999 Now, we want to change the targets, 99:59:59.999 --> 99:59:59.999 instead of the IK target, I'm going to "pos" the left position, 99:59:59.999 --> 99:59:59.999 and I'm going to pos the right position to the right foot. 99:59:59.999 --> 99:59:59.999 And for the rotation, I'm going to pos 99:59:59.999 --> 99:59:59.999 the new Quaternions I made for the new rotation. 99:59:59.999 --> 99:59:59.999 So, now that we have set this up, we need a way to say... how to know where to place 99:59:59.999 --> 99:59:59.999 our foot, and what rotation it will have. 99:59:59.999 --> 99:59:59.999 So I'm going to make a new Transform, 99:59:59.999 --> 99:59:59.999 which I'm going to name left foot, 99:59:59.999 --> 99:59:59.999 and the one for the right foot, I'm going to name right foot. 99:59:59.999 --> 99:59:59.999 And then, for inside our Update, 99:59:59.999 --> 99:59:59.999 we will create two Raycasts that make a raycast down to the ground 99:59:59.999 --> 99:59:59.999 and see what are we hitting. 99:59:59.999 --> 99:59:59.999 So we need a "RaycastHit" variable, 99:59:59.999 --> 99:59:59.999 which we're going to say "leftHit", and we need a right one too, "rightHit". 99:59:59.999 --> 99:59:59.999 We need to change, to Transform from local position to warped position, 99:59:59.999 --> 99:59:59.999 the position of a left and right foot, 99:59:59.999 --> 99:59:59.999 so we'll create a Vector 3, and we will call this 99:59:59.999 --> 99:59:59.999 "lpos," standing for "left position". 99:59:59.999 --> 99:59:59.999 And then we will say "leftFoot.Transform," 99:59:59.999 --> 99:59:59.999 point Vector 3 dot zero. 99:59:59.999 --> 99:59:59.999 And this will transform the local position to world position. 99:59:59.999 --> 99:59:59.999 And for the right foot we create "rpos" for "right position," 99:59:59.999 --> 99:59:59.999 and then we will take the right foot. 99:59:59.999 --> 99:59:59.999 So, now we have our positions, we need to do our own raycasts. 99:59:59.999 --> 99:59:59.999 We know for the left position will be left position, 99:59:59.999 --> 99:59:59.999 we know we want to do the Raycast downwards, 99:59:59.999 --> 99:59:59.999 we want to save it in left hit, 99:59:59.999 --> 99:59:59.999 and the distance... we can play a lot 99:59:59.999 --> 99:59:59.999 with the distance, but I'm going to use 1. 99:59:59.999 --> 99:59:59.999 And also, even though we are doing 99:59:59.999 --> 99:59:59.999 a raycast from the ground, you have to keep in mind that 99:59:59.999 --> 99:59:59.999 we might also hit our own collider. 99:59:59.999 --> 99:59:59.999 So, when we do the raycast toward the ground, 99:59:59.999 --> 99:59:59.999 and if we hit something, that means we have a left foot position. 99:59:59.999 --> 99:59:59.999 So we do a left hit dot point. "leftHit.point" 99:59:59.999 --> 99:59:59.999 And then we have a position for [our K gone ?] 99:59:59.999 --> 99:59:59.999 We need the rotation, and that will be "leftFoot.rotation" 99:59:59.999 --> 99:59:59.999 But we can't just do "leftHit.normal" because 99:59:59.999 --> 99:59:59.999 this is a vector 3. 99:59:59.999 --> 99:59:59.999 So we need a way to transform that into a Quaternion. 99:59:59.999 --> 99:59:59.999 You can't do a "Quaternion.euler" also, 99:59:59.999 --> 99:59:59.999 because it won't have the results you want. 99:59:59.999 --> 99:59:59.999 So what we need to do is take our Quaternion and make it from pass the transfer. 99:59:59.999 --> 99:59:59.999 The top, with our left hit, dot normal, 99:59:59.999 --> 99:59:59.999 and we multiply this by transform dot rotation. 99:59:59.999 --> 99:59:59.999 Now, if you don't understand this, don't worry. 99:59:59.999 --> 99:59:59.999 Quaternions are a little bit difficult to understand. 99:59:59.999 --> 99:59:59.999 So we need the same for our right foot, OK. 99:59:59.999 --> 99:59:59.999 Pos the right position, pos the right hit, 99:59:59.999 --> 99:59:59.999 and we want the right F position, and the right F rotation, 99:59:59.999 --> 99:59:59.999 and instead of the left hit, we need the right hit, dot normal. 99:59:59.999 --> 99:59:59.999 And just like that, if we go back... 99:59:59.999 --> 99:59:59.999 No, before we go back. 99:59:59.999 --> 99:59:59.999 We haven't set this up, 99:59:59.999 --> 99:59:59.999 so if we hit play now it will give us a null reference error. 99:59:59.999 --> 99:59:59.999 And that is because we haven't set this up 99:59:59.999 --> 99:59:59.999 so the easy way to do that is, 99:59:59.999 --> 99:59:59.999 since we know we have a humanoid, 99:59:59.999 --> 99:59:59.999 we can say get bone transform, and 99:59:59.999 --> 99:59:59.999 call it "human body bones" in animator, 99:59:59.999 --> 99:59:59.999 and say we want the left foot. 99:59:59.999 --> 99:59:59.999 And it will be the same for the right foot, 99:59:59.999 --> 99:59:59.999 and we have set up our transforms. 99:59:59.999 --> 99:59:59.999 So. 99:59:59.999 --> 99:59:59.999 Let's save, let's go back. 99:59:59.999 --> 99:59:59.999 And if I hit play, 99:59:59.999 --> 99:59:59.999 we will see that he's actually lost his legs, 99:59:59.999 --> 99:59:59.999 and we are probably getting errors. 99:59:59.999 --> 99:59:59.999 Now, let's see what we forgot. 99:59:59.999 --> 99:59:59.999 There are two problems over here. 99:59:59.999 --> 99:59:59.999 One is the Q-none, and this is because 99:59:59.999 --> 99:59:59.999 one of our Quaternions is returning "000". 99:59:59.999 --> 99:59:59.999 So, the Q-none error is about Quaternions. 99:59:59.999 --> 99:59:59.999 Let's open up our first left foot. 99:59:59.999 --> 99:59:59.999 This one will get the error because 99:59:59.999 --> 99:59:59.999 we can't find the left foot over here. 99:59:59.999 --> 99:59:59.999 That means something is wrong. 99:59:59.999 --> 99:59:59.999 Let's click the pos, and let's hit play again. 99:59:59.999 --> 99:59:59.999 We get the error once again, 99:59:59.999 --> 99:59:59.999 but we take it on the other foot. 99:59:59.999 --> 99:59:59.999 Let's see where the error is. What did we forget? 99:59:59.999 --> 99:59:59.999 It's probably because ... it hasn't already set up the animator, 99:59:59.999 --> 99:59:59.999 and there is no avatar. 99:59:59.999 --> 99:59:59.999 So I'm going to use ... to drop, minorly, the avatar. 99:59:59.999 --> 99:59:59.999 And put it over here, 99:59:59.999 --> 99:59:59.999 and let's see if we get the errors right, now. 99:59:59.999 --> 99:59:59.999 We still get an error. 99:59:59.999 --> 99:59:59.999 Let's 'comment' out our rotation. 99:59:59.999 --> 99:59:59.999 Since it's a problem with our rotation. 99:59:59.999 --> 99:59:59.999 Let's comment this out. Saved. 99:59:59.999 --> 99:59:59.999 Let's go back. 99:59:59.999 --> 99:59:59.999 And, now we see that we have our character 99:59:59.999 --> 99:59:59.999 is moving our feet and he's sticking to the ground. 99:59:59.999 --> 99:59:59.999 When he's not moving, we can see that his rotation, the IK will always work. 99:59:59.999 --> 99:59:59.999 In our characters crib over here, 99:59:59.999 --> 99:59:59.999 we are also using physics, 99:59:59.999 --> 99:59:59.999 and we do changes from inside the scripts, 99:59:59.999 --> 99:59:59.999 so I'm going to close this. 99:59:59.999 --> 99:59:59.999 And let's see over here. 99:59:59.999 --> 99:59:59.999 You see that he sticks to the ground, 99:59:59.999 --> 99:59:59.999 because we're doing the raycast towards the floor. [IK/OK] 99:59:59.999 --> 99:59:59.999 Let's see where the error for the Quaternions were. 99:59:59.999 --> 99:59:59.999 The problem with our Quaternion was 99:59:59.999 --> 99:59:59.999 even though we asked for our Quaternions 99:59:59.999 --> 99:59:59.999 to go from one rotation to the other, 99:59:59.999 --> 99:59:59.999 but they were null, meaning that 99:59:59.999 --> 99:59:59.999 we didn't have any rotation upon those. 99:59:59.999 --> 99:59:59.999 And the way to fix that is simply, we are taking the left foot ... 99:59:59.999 --> 99:59:59.999 and the left foot rotation will be, the left foot rotation, 99:59:59.999 --> 99:59:59.999 and for the right foot, will also be the right foot rotation. 99:59:59.999 --> 99:59:59.999 So let's go back, let's hit play, 99:59:59.999 --> 99:59:59.999 and for now I'm going to close 99:59:59.999 --> 99:59:59.999 the user input and the character movement. 99:59:59.999 --> 99:59:59.999 And I'm going to take a small cube I have over here 99:59:59.999 --> 99:59:59.999 and bring it over here, 99:59:59.999 --> 99:59:59.999 and I'm going to put it underneath our character. 99:59:59.999 --> 99:59:59.999 And you can see that it moves 99:59:59.999 --> 99:59:59.999 But we can't see his feet, 99:59:59.999 --> 99:59:59.999 so let's add a little offset. 99:59:59.999 --> 99:59:59.999 Let's make it public and 99:59:59.999 --> 99:59:59.999 we're going to sat, read the public. 99:59:59.999 --> 99:59:59.999 Let's say offset Y. 99:59:59.999 --> 99:59:59.999 And then when we set our position, 99:59:59.999 --> 99:59:59.999 we will say, we take the left position, 99:59:59.999 --> 99:59:59.999 plus a new vector 3," 0,offsetY,0". 99:59:59.999 --> 99:59:59.999 Then once again, 99:59:59.999 --> 99:59:59.999 Let's go into our third person character 99:59:59.999 --> 99:59:59.999 and set the offsetY to something like, point 12 (0.12) 99:59:59.999 --> 99:59:59.999 and let's hit play. 99:59:59.999 --> 99:59:59.999 Let's bring our cube once again. 99:59:59.999 --> 99:59:59.999 And as you have already seen, he moves. 99:59:59.999 --> 99:59:59.999 He's now going up, because we have a collider over here. 99:59:59.999 --> 99:59:59.999 Let's make this a trigger 99:59:59.999 --> 99:59:59.999 so that he's still moving, 99:59:59.999 --> 99:59:59.999 because we are making a raycast also 99:59:59.999 --> 99:59:59.999 from our character movement script. 99:59:59.999 --> 99:59:59.999 So I'm going to close the user input ... 99:59:59.999 --> 99:59:59.999 and... that was probably a bad idea... 99:59:59.999 --> 99:59:59.999 Let's try this again. 99:59:59.999 --> 99:59:59.999 Let's bring this over here. 99:59:59.999 --> 99:59:59.999 Let's hit play. 99:59:59.999 --> 99:59:59.999 And then I'm going to make him a kinematic 99:59:59.999 --> 99:59:59.999 and I'm going to say he's a trigger. 99:59:59.999 --> 99:59:59.999 And I also want to close the user input 99:59:59.999 --> 99:59:59.999 and the character movement script for now. 99:59:59.999 --> 99:59:59.999 When I bring my cube from beneath, 99:59:59.999 --> 99:59:59.999 you will see that he's not only placing his feet, 99:59:59.999 --> 99:59:59.999 he's also rotating them along the correct position. 99:59:59.999 --> 99:59:59.999 Keep in mind if it's something like this 99:59:59.999 --> 99:59:59.999 you will probably need to play a different animation. 99:59:59.999 --> 99:59:59.999 IK is not for animating, 99:59:59.999 --> 99:59:59.999 it's not going to save you from animating stuff. 99:59:59.999 --> 99:59:59.999 Although it's pretty capable. 99:59:59.999 --> 99:59:59.999 And the way you use it could be pretty capable. 99:59:59.999 --> 99:59:59.999 You will also need animations 99:59:59.999 --> 99:59:59.999 to further prove the IK. 99:59:59.999 --> 99:59:59.999 So IK is mostly for correctional use 99:59:59.999 --> 99:59:59.999 and not for, as something you use 99:59:59.999 --> 99:59:59.999 independently from animations. 99:59:59.999 --> 99:59:59.999 So, now that we see how it works when it's stationary, 99:59:59.999 --> 99:59:59.999 let's see how it works when we are moving around. 99:59:59.999 --> 99:59:59.999 I'm going to focus my view on his feet, 99:59:59.999 --> 99:59:59.999 so that we know what is happening. 99:59:59.999 --> 99:59:59.999 Something like that. 99:59:59.999 --> 99:59:59.999 And I'll hit play and I'll move around. 99:59:59.999 --> 99:59:59.999 Keep in mind, when we are running 99:59:59.999 --> 99:59:59.999 we don't have any floats, 99:59:59.999 --> 99:59:59.999 we don't manipulate the floats of our curves, 99:59:59.999 --> 99:59:59.999 of our animator. 99:59:59.999 --> 99:59:59.999 So, he doesn't influence the IK, 99:59:59.999 --> 99:59:59.999 but if I hit shift when we are walking, 99:59:59.999 --> 99:59:59.999 you will see his left foot walks a little better 99:59:59.999 --> 99:59:59.999 since we fixed that. 99:59:59.999 --> 99:59:59.999 We have more control, we made it 99:59:59.999 --> 99:59:59.999 not to be influenced so much by the IK. 99:59:59.999 --> 99:59:59.999 And the right foot we left (alone) 99:59:59.999 --> 99:59:59.999 so that we can see the difference. 99:59:59.999 --> 99:59:59.999 And now if I'm going up the ramp, 99:59:59.999 --> 99:59:59.999 you will see that he positions his feet 99:59:59.999 --> 99:59:59.999 to the ramp. 99:59:59.999 --> 99:59:59.999 This is a lot influenced by the IK. 99:59:59.999 --> 99:59:59.999 If you play with the values, 99:59:59.999 --> 99:59:59.999 and put them exactly as you want, 99:59:59.999 --> 99:59:59.999 you'll get much better results 99:59:59.999 --> 99:59:59.999 than from what we already have over here. 99:59:59.999 --> 99:59:59.999 Typically in games mostly, they are 99:59:59.999 --> 99:59:59.999 not so dependent on the IK, and 99:59:59.999 --> 99:59:59.999 a lot of the time they just change the animation 99:59:59.999 --> 99:59:59.999 and just correctly place the feet 99:59:59.999 --> 99:59:59.999 so that doesn't look ugly. 99:59:59.999 --> 99:59:59.999 Mostly when the character is sitting idle 99:59:59.999 --> 99:59:59.999 you'll see that they change his position. 99:59:59.999 --> 99:59:59.999 They enable the IK for him. 99:59:59.999 --> 99:59:59.999 Let's see how he will walk over here. 99:59:59.999 --> 99:59:59.999 Now, even though we have the IK open 99:59:59.999 --> 99:59:59.999 we also have the collider over here 99:59:59.999 --> 99:59:59.999 which doesn't let him pass over other objects. 99:59:59.999 --> 99:59:59.999 So if I close it, you will see that 99:59:59.999 --> 99:59:59.999 he's moving and he places his feet. 99:59:59.999 --> 99:59:59.999 If you spend more time setting up the floats 99:59:59.999 --> 99:59:59.999 and where exactly you want them, 99:59:59.999 --> 99:59:59.999 you'll have better results. 99:59:59.999 --> 99:59:59.999 Sometimes you'll see that the feet might 99:59:59.999 --> 99:59:59.999 even get some rotations that are 99:59:59.999 --> 99:59:59.999 not really natural, so you can fix 99:59:59.999 --> 99:59:59.999 how much of a rotation you want the feet 99:59:59.999 --> 99:59:59.999 to be able to do. 99:59:59.999 --> 99:59:59.999 If you go.. before applying the rotation 99:59:59.999 --> 99:59:59.999 over here, you can say, take the left foot rotations, 99:59:59.999 --> 99:59:59.999 let's take the Y and make it 0. 99:59:59.999 --> 99:59:59.999 This is just an example to show you 99:59:59.999 --> 99:59:59.999 how you can do it. 99:59:59.999 --> 99:59:59.999 It's not useful to have without testing first. 99:59:59.999 --> 99:59:59.999 Here you will see that whatever rotation 99:59:59.999 --> 99:59:59.999 we're having on the Y, he will return, 99:59:59.999 --> 99:59:59.999 he will always be 0. 99:59:59.999 --> 99:59:59.999 The rotation will always be 0.