6  Humanoid Root Motion Challenge Part 1

6 Humanoid Root Motion Challenge Part 1

Time for another challenge in this challenge what I’d like you to do is to create a swimming y boat so he can say that I’ve got the Y boat and I’ve got a treading water and a swimming animation the swimming also gets faster the longer you hold down the forward error. OK. So don’t be scared by this. This is exactly the same thing as we were already done with the walking animation. It’s just that instead of standing idle and walking we’re now treading water and swimming. So we’re just changing the visual aspect. All right. So pause the video now. Give it a go to resource files are attached to this like. Just grab them put them into unity and see if you can get your wife up to swim. So here we are in unity. And what I’ve done is brought both of the animations that I gave you into the project. What I’ve also done is just set up a sane way. I’ve got a ground appliance that’s just a big plane with a caustic water kind of effect on it just so that you can see the wobble moving around. Of course you don’t need to add that if you don’t want to. So first thing we need to do is put the ball into the scene. Now you’ll say you’ve got two different icons here for the war but the treading water and the swimming. So the one that has the skin on it is going to be the treading water one. So if we grab that and dragged into the scene we’ll get the why but now we’re looking from above it doesn’t matter which way you look from it and just see it better from Above all I think. So the camera is just fixed about it and that will allow the wall about to move around in the sand rather than following it with the camera. So with that done we now need to create a new animator controller for the Y boat. So what we’ll do in the project is create an animator control law and we’ll call it swim. We’re going to then inside of that. Let me just make this a bit bigger so you can see Add in that too animation so we’ll just drag the treading water one and the swimming one like that. Now they going to be linked so that when we’re swimming we go to animation stopped moving them again to go back to the treading water. So we make two transitions the same as Adal and walking and go from one to the other. Now they need to be triggered by a particular value. So we will add in a new Boole and let’s call that is swimming like that leave it turned off for now. So when it becomes true we want this way to transition. So select going from treading water to swimming and then you want to set the conditions for that to be. Is swimming is true coming back it will be. Is swimming is false so let’s add something false like that. OK so now let’s just go to air. Why Bush. We’ve done some basic stuff. We’ll put the animation up onto the wall I bought and then just press play to see if that’s working. It’s sometimes a better idea to do little steps and press play all the time than do the whole lot. And if something breaks you have no idea which bit broke so slick the wah. And we will now grab a swimming controller and just put it onto that and a motor control that automatically was placed on the y I book by unity because that’s what it does when you bring in if the X-File in. Right let’s just press play and have a look what happens. So we press play. We’re obviously treading water at the moment and now we’re not treading water. So what’s the problem with that. Well our animation isn’t looping so to fix that select the animations one in turn and first of all we’re going to do is sit them to be humanoid because we want them to be able to move around with the motion so while we’re in here we males will do that grab the rig and then you want to set that to human weight and then hit apply. And then at the same time we’re going to go to the animation tab and just go down a bit to get to loop time. Check that as well and then go down and apply it. And that will now give you a nice looping animation on that. Now because the treading water animation is already on the way but that kind of sort of you know together as such. Then when you set the rig to humanoid you’ve sit the wobble to humanoid as well. Now for the single swimming animation it’s bot self we also want to set it to humanoid and click on apply and then we want to go into animation and loop that as well so that you can just keep swimming and swimming and swimming until you’ve released your Erika which will be driving that. So we’ve now got that applaud. Let’s just press play and see where we’re at. So the why but in this case them you just get down a bit closer they’ll see it in or in the same view. This is the treading water on a mission which is really nice and we can see now if we click on that and have a look over in the animator that Al animation is indeed looping and there’s nothing at all that’s going to trigger it because we haven’t written any code so we’re doing fine. OK. So stop playing now for the code. What I’ve done is I’ve taken the drive script that we used for for standing Ortal and walking and running is exactly the same. So let me just open that up and show you here it is it’s got speed rotation speed current spate it’s still cold drive doesn’t matter you could call it swimming if you wanted to. It creates an animator and then gets hold of the animator that is on the character the same character that the script is on. And then we go into our update which is doing the same thing as before. The only thing that you need to change in this code is is swimming. So this was walking before if I remember rightly I’ve changed it to is swimming because this has to match exactly what this is. Same spelling same capitalization. Now translation tells us if we’ve got the arrow came up with Dan aira case prestes and if we have then the translation value will not be equal to zero. Therefore we will see it swimming to be true. And otherwise we then do. Swimming is false. The other thing that’s in this code if you’ve got it directly from the previous walking running with why but where the speed was speeding up is that you’ve still got this speed thing going on. He were setting a spade value according to the current speed which is an accumulating speed cassette. Each time this loops around and we got the cape just keeps adding the translation value to current speed which is going to get bigger and bigger and bigger and bigger until you take your hand off the cable or at which point we end up down here at current spade initialized back to zero again. Now the thing is we’re setting a float called spade on out on a mission control law. But we haven’t created that yet. So let’s do that as well. So a spade with a capital S.. Let’s just go over to our animator in here. Create a float and we’ll call it speed with the capitalists and that’s going to be the spade of our swimming not our treading water. So click on the swimming which is this one here. It’s the F key in there if you want to focus on something then either in the Inspectah in the speed multiplier forgotten that on and it will pick up automatically that we have the flight speed sitting over there in that parameter list and then apply spade to the swimming animation. All right so now what do we do with that code that we’ve written. Well first of all make sure that you say this and then we can just close it down so we don’t need it anymore and drag and drop drive onto your y boat. Select the Y bought and just make sure that the drive script is now on which is case I press play and we should now be able to swim around with the case. Sort of I just noticed this is a few issues. First of all the swimming is just stopping which is an interesting effect if you want to do that and the other thing is if I just press play. OK. So is treading water. Now I’m hitting that Erika now and nothing’s happening. So I know that both of these issues are being caused by exact same problem. If you click on treading water how we want that to exit strategy out of that animation when we hit the barricade so we don’t want to wait to finish the animation. It’s just got to exit way up to and go to swimming. So in order to do that click on the transition going from trading to swimming over an inspector you want to turn off has exit time and then the swimming one. The reason why the swimming one is stopping mid step is because the speed suddenly gets set to zero. When you take your finger off the Eric key which doesn’t allow that animation to finish running. So a zero spade in your multiplier for your animation will just stop it halfway through. And because we haven’t turned off the exit time for that then it stopped. OK. It will not transition back to treading water until it gets to the end which it can’t because it has a spate of zero. So let’s go on the transition going back and let’s just turn off has exit time for that as well. Now let’s press play again and see how it all swings going. That’s good. And we’re getting incredibly fast the rotation is still working to turn this around. It’s probably a little bit too fast isn’t it for swimming but we can fix that quite easily in the code. But I want to just show you something else. First let me press play again and I’ll go back to the scene. I want to get a little bit closer. Just watch as I press that’s not going to let me play there. I’m going to press play and then try and pause it. Now have a look here. We’re in the middle of swimming. Look at this fort. This can be a real problem when one animation isn’t quite long up probably with your avatar that you’re using. Now we want to ensure that in this case if you select the swimming animation this one didn’t have a skin with it. It’s kind of like free and it’s got its own avatar. If you select Reeg in the inspector and you’ll see underneath where you said it. Humanoid it’s got Avatar definition create from this model so it’s creating its own avatar which is not a good idea in this case as we can see that the foot’s gone all funny. So to fix that if you just drop this down for Avatar definition and select copy from other avatar you can then use the why bots Avatar. So just click the source of that. Now the source is the treading water one that’s the avatar that’s got the skin on. So we’ll select that and hit apply. And now we’ll just restart this all and see how a swimming is going OK. So if I can again pause this while it’s swimming and then fine the wobble areas. Right foot is fixed as you can see there. What was it that for. Whichever way they’re both good on day. OK so that’s all working quite nicely. And let’s just go back to play now the other really weird thing is that he can be Adelie swimming around which is probably a little bit unrealistic if he wanted to control the speed of the swimming. You can go back to your drive code and we just need to modify what’s happening in this. Let me just grab that script for you here is. Now we just need to find elf swimming Valley which is going to be this current spade down here and we could feed through current spade and multiply it by point five if floating value. If we want to see how the current spade so that it’s not going to be as drastic as you just saw so much at point four that’s how it looks. I’ll save that. Go back to unity and press play. And now spading up is a lot less as you can see there. Now if that is just way too fast. Still you could put some kind of a cap on it rather than just restricting it with that sort of dampening effect. So let me get rid of this is just another way to do it. What I’m going to do in this code is just give you a little bit of logic to help you if current speed let’s say it becomes greater then what’s a good value do we think 5 then we’re going to sit current speed equal to 5 so the fastest it’s going to get us far spade is concerned is FOB and that’s where we’ll cut itself off and stay stuck at 5. Just what sort of line here say that. Going back to unity and press play. And them old Chinese swim. So that’s the fastest he’s going to get. And if you have a look over here in your parameters you watch that value of space there you’ll see that it gets to five and then it stays at five it still goes down because we’re setting it back to zero and we take your hand off the keyboard. Otherwise it’s going to be five. And that’s not bad. That’s pretty good spade for him. OK. The final thing if you want to is to add some nice water. Now we’ve got a sort of a ground plane here but these are sort of surface water. So let’s do that. There’s some really nice water that comes in an asset pack so gumped assets in the mine menu. Click on import package and you want to bring in environment. So in that there’ll be a whole heap of things. There’s trees and let’s have a look through here. There’s probably a lot of stuff that you don’t even need so there’s some trees rocks and things like that for creating landscapes and you could turn them all off. But the most important one is you want this water coming in sawdust to bring everything in to make sure that you’ve got us. And inside of that you’re going to find some water prefabs that you can put into your sayne. Now we’re going to want to be focused on the why Bauch itself in the same when we place this water so that we can see where it’s gone. So just double click to find my war book which is there and then we’re going to fall in the water. The water is going to be under standard assets environment. And then let’s say we’re looking for water and there’s a few different waters that you can pick from just go for the basic water. Otherwise there’s a lot of other settings in that for the other type of water. Now you’ve got to water not time and you’ve got a water diatom let’s say that it is daytime here. So a drag and drop that water object and you can see here that it’s interacting with that ground plan that I’ve added not so rock because we can lift it up. Later on you’ll see that it’s also round in nature and you can make it bigger as well but it will stay round. Now if like getting closed is let me just rotate my seat. It is sitting on the bottom and interacting with that ground plane. So let’s just lift it up like that. Now the boat is kind of in the water if you want to make it a bit bigger. You can of course hit the Akeda resize it and just make it bigger pends on what you want to do with it. So now we’ve got that sand underneath the water with the caustic effect on it. And then we’ve got the water above. But is the water in the right place for the Y but let’s just press play and have a look on auto. You might then need to just adjust it a bit and give it the same case so we can see when it’s running when you’re treading water you probably have your hands sort of at the top of the water and you might want to get hold of that water. Use the W-K again just to move it around to where you might want it to be which might be about they maybe just a little bit low. Now this will change these high. When you stop playing it will just sit back again if you want to remember that high. Then in the inspect just grab hold of the y value here and then you can reset it when you’re not playing so it’s permanent. But what I’m interested in now is when I go to swimmy from under the water on we train so I might take a little bit of tweaking to get that just perfect. And we’ll work on that in the next video.

Leave a Reply

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