Unity3D & Mixamo Character Animation With Mecanim

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hey coders Darren here and I'm going to be finally continuing the Beckenham tutorial series from unity3d I know it's been about a week since I've gotten into this but I have been a little bit busy but this is a really requested topic so I've come back to at the Beckenham character animation tutorial and we're going to be using mix MO to do this now mixing mo if you don't know is a great tool for taking some free assets for characters and free animations that are actually really high-quality triple-a quality and we can take those for free and bring them into our unity project and get a quick prototype going so what we're going to be doing in this tutorial is first let's go ahead and log in so create an account if you don't have one already I'm going to put my credentials in right now and what we're going to be doing is getting a simple character animating basically just running and strafing back and forth we're going to be using the eight directional character system from a previous tutorial so what we want to do is just find a simple but simple locomotion pack so what I did was I just click store there and then we have this page come up that gives us a lot of sort of prefabs for different characters and different animations so here we have the pro magic pack and the light magic pack these will give us actual magic animations so whether it's doing something with their hands and shooting fireballs those animations are included in these pro rifle pack will give you animations such as running and shooting or crouching with a rifle in your hand and so a lot of these sort of follow suit and you get really great animations with these now in this tutorial we're just going to be doing an introduction to mix ammo so what I want to do is go with a basic locomotion pack now what we can do is click the female locomotion pack I already have I've done this several times now to prepare for this tutorial but so I already know the character I want to use but you can feel free to choose a different character than mine and you can still follow along with the tutorial now what I have here is a character selected I can go ahead and change the character so if you want to use a different character you can click on mix them characters here and then you can just sort of scroll through until you find a character that you want to use if you want to follow along and they have it looks like four pages here so I'm using Eve right here on the top right and what we want to do to set Eve up is give her a few animation so I'm going to click customize pack right here and what we can see here is we have a few options to manipulate this strafe animation now the first thing I want to do is click this checkbox in place now if I uncheck that we can see the animation is actually moving the position of Eve and that's not something we want unity and unity we're going to be we're going to be modifying the position of Eve through code through script through character controller so we don't want the animation to be moving her position so what we do is we check in place and now we have this nice animation running in place and it's going to look natural because we're actually going to be moving her position along the direction that she's facing now we can change other settings on these sliders such as overdrive and that's going to slow down or speed up the animation totally up to you if you want to modify these things I'm going to leave it right back at fifty armed spaces another thing that we can modify so we can bring our arm space really close in to our sides and you can get some really silly looking things coming out of this for sure so that's sort of giving you an introduction to the flexibility of this incredible resource we can even trim this so that we get different frames in our animation I'm going to leave it at the default because I don't want to mess too much with that but we're going to go through these animations and make sure that they're all in place if they're moving we want to make sure they're in place now the running one should be in place the jump isn't going to be modified they don't even give us the option they're obviously idle is already in place so we don't have a checkbox for that now left walk straight strafe also right strafe walk and walking now in this tutorial we're only actually going to be working with probably left and right strafe and we'll be working with run and that might be it so running and left and right strafe and also idle of course we're not going to get into jumping this is just an introduction and we may go deeper into this character a little bit later in future tutorials now one thing I do want to do is see if I couldn't rename these I'm not sure if I actually can either when these get brought into unity they're not actually going to have the name so this animation will actually be called left strafe they're all going to be labeled as mixed mode comm I'm still trying to figure out why that is and if some of you know definitely leave comments in the comment section but otherwise I'm just going to go ahead and click view and download now you might run into some problems with loading you might get stuck in some endless loading loops with certain browsers I found that using Mozilla Firefox for Windows works well and I think Safari for Mac OS works well chrome tends to have problems at least for me and you might have the same issues as well so I recommend using Firefox trying that out but what you'll do is click Q download we can change the format to FBX for unity everything else can stay default and we click Q download then this will show up as processing and hopefully if you don't run into an endless loading loop then you will eventually be able to actually download that package now once you download the package you should have the in progress folder and your downloads unless you renamed it and the mix of my web browser now we're just going to extract all right into our downloads folder and I'm actually going to rename this to mix them oh this is going to be my mix of a folder and unity and then what I'm going to do is just drag that into my assets folder just like this that's going to load a little bit then we can take a closer look at exactly what it is that we got from that so you'll probably get this message showing up about a normal map you can just click fix now and that'll get rid of that error I mean it really wasn't an error mostly just a warning but regardless we got rid of that so let's open up the mixin Moe folder and then we see all of these FBX format file types for each of our animations so you might think this is like a little bit cluttered and it is but essentially what we have is our main character this is what we're actually going to be dragging into our scene and then we have all of the animations right here so if we open these up you can see as I was saying we have mix in my comm and all of the animations are called that so I'll do my best throughout this tutorial to clarify exactly which animations I'm using but if you click on the animation it will highlight the FBX so you're using so you can tell when we click mix mo come here it will highlight left strafe in place so again I'll do my best to make sure I'm clarifying that as I talk about these animations so we want to make sure that all of these animations for lack of better term are pointing to the correct avatar if you open these up each one of them have an avatar so jump avatar idle avatar now the anim the the prefab I'm sorry the prefab that we're going to be using for Eve is this one and we're going to be using the evap ATAR we want to use one avatar we're gonna have one centralized avatar for all of our animations to point at so what I want to do first of all before I get ahead of myself I want to select all of these FBX file types I want to click on rig and I want to make sure they're all humanoid and then I'll just click apply so once that finishes processing we're going to set it up in such a way that all of the animations are pointing to the same avatar now what I'm going to do is deselect Eve and I'm going to open up so I'm going to open up Eve right here so I have access to her to her avatar and then while I'm selected on all of the animation FBX is I'm going to change the avatar definition from create from this model to copy from other avatar now we get this source avatar field showing up that's empty and all we're going to do is drag this avatar into that the source field for each one of these and then I'll click apply and then at this point we should be set up and ready to go we shouldn't have to do much else now when I click Eve next to the configure button we have this check mark indicating that we are ready to start working with these animations now first before we give forward make sure that you have a test scene set up so that we can make sure we're saving our work otherwise let's go ahead and add a plane to our scene it looks like my lighting is a little bit messed up so I'm going to click lighting and click generate lighting sometimes that can happen and then what I'm going to do is make sure that this plane is sizeable so we have enough room to run around I think I'm actually going to add some cubes as well so we have sort of reference points when we're actually running around and really quickly just bear with me I'm going to sort of set up this scene a little bit I'm going to add see yeah we do have shadows there so I'm going to add some color here I'm just going to create a quick material for this cube just so I can give it a color other than white I think I'll create another material for the ground as well so we'll also have a ground material okay on the ground we'll just say is some I tend to use dark colors for the ground I think it looks a little bit better you can actually leave the key wide if we want but I already created that material so I'll just add that red color okay now what we want to do is go into mix ammo' and take this Eve character which is ready to go and just drag her into the scene so this is going to be our character that we're going to be running around with and animating and actually if we press play now she should be staying in T pose which is great now what we want to do is go ahead and create an animator controller for her over here we can see that it already has an animator component on it we just need a driver controller to manage all the animations so I'm going to create an animator controller I'm going to call this Eve animator controller and I'll just drag that on to this component field ok now whenever I click play we are going to see unity try to manage these animations basically this is what's going to happen if we don't actually have any animations in our animator controller now if I click animator we can see we don't have any states being active so this is unity making its attempt to do something with the fact that it has an animator controller with no animations but this does mean this is a good sign because it does show that our muscles for our rig are actually showing up or actually working properly but it with this obviously isn't the behavior that we want right let's start off easy let's just start with an idle animation now if you haven't seen the previous tutorials go ahead and check those out I'm not just going to be creating States here I'm going to actually add a blend tree now blend trees are a way of merging States animation States so that we can sort of blend between two different animations so imagine I'm strafing and I'm also going forward we might expect our animation to sort of compensate for those two animations and give us something that makes us look like we're running diagonally which is what we would we would typically want especially in an 8 directional character system which is what we're going to be using for this tutorial so what I'm going to do is go to create state and say from new blend tree now we can just double click this blend tree and go into the blend tree just like this and to start off simple all I want to do is add the idle animation so I'm going to right click on blend tree and click add motion now over here in our inspector we can see that we have a motion added our blend type is 1d which is fine for now since all we're doing is idling now let's go ahead and add this motion so I'm going to open up idle over here and drag that animation clip over to the motion and we can see that that's actually showing up over here now in our blend tree so we actually have a connection established from our blend tree to our animation now remember I said for some reason all of these are called mixer mode calm I will work on that try to find a solution and if if any of you know why that's happening let us know in the comments or hop on our discord Channel and let us know what's going on there ok now if I press play we should see the idle animation and let's go ahead and take a look at that and you can actually even see her breathing so we do have confirmation that that animation is going through it doesn't look like it's looping because she just stopped breathing so let's go ahead and click on the idle and we can click on this idle prefab and click on animations and mix em Oh gives us some settings here to modify the animation a little bit for idle we just want to make sure this is looping right so I'll go ahead and apply that I'll click play again and she should keep breathing she shouldn't stop breathing and that's going to indicate that our looping is actually working there so I'll let that run for just a second and it looks like she just looped right there okay so that looks pretty good but now what we want to do is get her running around right so we need to be working with the forward the running animation so running in place also strafing in place so that's going to be working with left strafe in place and right strafe in place before I do that I want to make sure I bring in my camera and character controllers and I'm going to be bringing these in from a previous tutorial called the a directional character system now it's worth noting that our patrons do get our source code and our projects for free for contributing to Renaissance coders and if you want this source code then go ahead and check out our patreon you can also get some other great rewards for doing that but we are going to be using those and if you want to check out the tutorial for the eight directional character system I will provide a link to that let's go ahead and add our Mario controller onto Eve okay so we're all set up there I'm going to reduce the speed the velocity of this to two and I'm going to set the Y to five this is for the camera settings and the z2 let's just say the Z is negative four and let's say the the Y is a little bit closer we want to have a little bit of a closer look to our character let's press play actually I do need to drag Eve and to the target component there okay now over here on our game view we have a good look now I do have this jitter and I want to address that right now let's go into our camera controller this jitter happens sometimes whenever the character controller or I'm sorry whenever the camera controller is in late update but I actually have the camera control and fixed update so if I change that's a late update I wonder if that's actually going to fix that jitter that we just saw yeah that's so weird so it's actually fixed so this is a weird issue and I'm actually going to I'm going to extend this problem to you coders if you're running into this issue let me know because sometimes it works for me in fixed update and sometimes it works in late update so if you have this camera jitter and you know what the issue is let me know I honestly think it's just an issue with unity because again sometimes fixed update works and sometimes the late update works and you guys just saw a fixed update there wasn't working and I switched it to late update and that did work now to add to that unity does say that late update should work so if late update is the one that works now I'm totally fine with that okay so we have our camera and character controller set up let's go back to our animations and see what's going on there what we need to do is add the running and these strafing animations so let's get running forward and running backwards first and that's going to be sort of an introduction to blend trees for us so let's add a new motion here so this motion is going to be this motion is going to be running in place so let's go to mix mo and look for running in place and we're just going to drag mix mo on to this and we also want one for running backwards now we can see here we're still in 1d now we are going to want to move to 2d because that's going to give us blend on two access points for the horizontal a and D keys and the vertical W and s keys if we look at this blend we can see if we modify this blend then we go just look at the color so for right here 0.5 those are both the same color that's indicating to us that both of those animations are being perfectly blended okay now what I want to do is change this blend type to simple 2d directional and I need to add a parameter so first we're going to have a blend X and then we'll also have a blend Y so let's add this blend Y and these are going to be directly mapped to our character inputs so we have character inputs for horizontal movement and vertical movement so horizontal is going to be mapped to blend X vertical is going to be mapped to blend Y now I need to go in here to my inspector and have this blend Y and if we look over here in our blend tree now we have to blend sliders which is exactly what we want okay now I need to go down here this so this makes mo calm is my idol this mixed-mode calm is my running in place we can see that highlight in the asset panel now if we're running forward then our positive Y should be one so that is a vertical input of 1 which is if we're pressing W now we also want to be running that animation when we're pressing s because when we press s we're actually running back towards the camera let me press play to demonstrate that really quickly so if I'm pressing forward I just go forward if I'm pressing s I should be turned around coming back so we also want the same running animation but we want that to be working whenever we're also at negative 1 on the pause Y here so what I want to do is set set 1 here and then I want to add a new motion so add a new motion and this motion is going to be the same máximo calm but this one is going to be negative 1 ok now if I press play we should see something start to happen they still don't still no animation so the reason we don't have any animation yet is because we're not actually modifying the blend Y so I actually need to be modifying this blend Y from gripped we will get to that actually so let's go ahead and go to our Mario controller okay and the first thing we want regardless of what character controller you're using we want a reference to our animator so I will not animation but animator that's going to be our animator controller so animator an M and n start we can initialize this by calling get component so Anam equals get components animator just like that now we're already modifying the input X and then put down Y so what I want to do is simply say an M dot set float blend X and that's going to be equal to input X and an MDOT set float blend Y infidel wine now if you're confused about what we're doing here I recommend checking out some of the tutorials earlier in the series we sort of go through this and what this actually does in those tutorials but we're just sending the we're just setting the blend XM blend Y parameters that we just created in the animator and we're mapping that directly to input X and input dot Y now we do want interpolated values in this case in other words we want values from negative 1 to 1 where we aren't just going in discrete steps so we will have values in between negative 1 and 0 and in between 0 & 1 so by removing get access raw and replacing that with get access we get those interpreted values now let's go back to unity and see how those are actually mapping to these sliders so whenever I actually play the game let's go ahead and watch these sliders so when I press forward we can actually see this blend dot Y slider moving okay so it looks like for some reason because we are trying to map to the coordinates to simply the only the Y blend the animation actually isn't playing so this is just an example of some weird stuff that we can run into with making them what I'm going to do is sort of fill this out so let's go ahead and just add the motion fields for the strafe and see if that fixes things so I'm going to add two new motion fields and the first motion field actually auto-set so this first motion field we want the X blend to be negative one that's going to represent the left strafe then we want a blend X of positive 1 with a blend Y of zero and that's going to represent our right strafe so all I need to do is drag these onto all I need to do is jog these on to our animation clips so let's take our left and that's going to go on negative one and we'll take our right and place that on the positive one now when I move the blend X we can see these circles expanding and shrinking that represents the actual blend how much of that animation is actually being shared at that moment if we go up we can see we have three being shared here and that's going to give us more of our diagonal movement when we further away we are totally separated from the idle animation so I'm looking at this little model down here and the inspector so let's go ahead and press play and see if that fix things for us okay so actually didn't that's really strange I think that's just one of those things that you run into with meckenheim and now I'm actually not able to it looks like I can't even get my strafe animation to work correctly now this again these are just issues that we run into so what I want to do is set some of these settings in the Meccan em animation so what we're going to do is go through these animations and just set some default settings these are settings that I always use so what I'm going to do is set route transform rotation and both of the root transform positions to bake into pose I do that with all of these now if you're wondering what this is it just means that the the position isn't going to be modified by the animation for instance if we have the jump animation we will want to uncheck this because we won't want the Y position to be modified by the animation but again since we're baking it into pose the animation is not going to affect the position or the rotation of our actual transform on our character so I'm going to apply this to left strafe in place and of course we want loop time on that and then I'll do that on right strafe in place and we can see here over on the green that's just saying that the loop matches which is great sometimes you'll see that the loop doesn't match if we bake into pose but on all of these that's looking pretty good so we should get a decent looking animation as the outcome of this so I'll go ahead and press play okay we can run forward it looks like that loop is going and it's working I'll turn around and we're running back towards me now the magic of the blend tree comes in whenever we're actually pressing two keys at the same time so if I press forward and then press a we're going in this diagonal and there's just this really smooth transition there's no real skipping between these animations as I'm running around that's really what you want now with this particular controller going between the two extremes of A and D shows to be a little bit troublesome for this animation so there's a little bit of a pause there actually turns around and goes back to our animation but this is a basic intro tutorial so I think this is about as deep as I'm going to go into it and in the next tutorials we may add some other things such as the turning animation the jumping let me know what you guys want to see if you want to if you want to you know move on from the mix mo animations and to something else let me know it's all about what you guys want and if you like the video then go ahead and drop a like go ahead and subscribe if you haven't I mean we're putting out some great content for you guys we were working our butts off day in and day out so if you haven't subscribed yet go ahead jump in our discord chat and ask us your questions there that's a great platform to communicate with us but otherwise thanks for watching and have a great day
Info
Channel: Renaissance Coders
Views: 71,861
Rating: undefined out of 5
Keywords: unity, unity3d, mecanim, animation, tutorial, how to, animate, beginner, unity animation, unity3d tutorial, unity tutorial, animator, unity 3d, unity games, unity animator controller, what is mecanim, what is animation, unity mecanim, c#, game programming, character controller, mixamo, game, unity character controller, character
Id: 256-LXzMt0U
Channel Id: undefined
Length: 26min 31sec (1591 seconds)
Published: Sat Jul 08 2017
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.