Unity MIxamo Character Animations (idle, walk, jump) - and how to add jump physics

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
[Music] hello and welcome to this tutorial in which we are going to look at a super simple way to create animated characters in unity and for that we are going to use mixim so if you found this video or you're going to video or any of my other videos useful please remember to like subscribe leave a positive comment below and of course leave a suggestion for any future content okay so the first thing to do is jump over into mixo so mixim used to be a separate company um used to be well I'm not going into the details the background of it way Adobe now own it so you can just create an account or just log in if you've already got an adobe account and it should bring you up something like this where we can choose a range of different characters um or we can choose a bunch of animations now I've just chosen this guy um seems to have crashed on me a little bit that's a bit annoying um already in the standard T pose so what I'm going to do is I'm going to look for a starting animation I'm just going to look for an idol animation so sometimes it's worth having a little play about having a look see what it looks like okay I just paed OBS and refreshed my page so there we go we can see this very subtle idle animation you can have a play about click on on the other animations and just wait until you're till you're kind of happy with one you know it's entirely up to you doesn't really matter at this point so what I'm going to show you is not the most efficient way of handling animations but it is a quick way of bringing something to whether you want to put a an animated character into your AR project or a VR project or just a normal game so if I just press download it's going to say fbx with skin 30 from second yep I'm happy with all of this stuff I'm just going to press download so this is going to download the entire mesh with the animation and this is the bit where it's not going to be that efficient let's say I now want him to walk uh again just like before I can go through them and choose into ones I like now it's coming towards the camera that's not ideal in games good for animation not for games so if I just press the ti the Box in place there we go I'm quite happy with that one so I'm going to download this one as well so again this is now a totally separate model with a separate animation excuse me with a tot separate animation so this is why it's not efficient because we're going to be taking up a lot of dis space that we might not want and I can play about with others by the way I could look for other things things and again I can take the in place button um what else do I want let's say I want a jump one so I'm going look for different kinds of jump I believe all these animations come from proper motion capture um so if you get to a point where where you want to do your own kind of animations um you can as in if you want to do your own motion tracking for example is organizations like roko um I can't afford a roko suit but if you're listening you want to sponsor this Channel please do feel free to send me want to to borrow for a while okay so um basically download the ones you want it doesn't matter how many you get for now U I'm going to close that down uh I using pixie Bay for some textures although I do recommend get your own cameras out and go and take your own photos to use as textures so I'm in unity um I've got a new project same as always a 3D core one uh I'm going to create a plane that's going to act as my ground I'm going to make sure this is in the z0 coordinates um I'm now going to just put this texture on now that's quite big I'm just going to I'm going to actually click on this and change the tille in and say give me 5x five um I know we can see the tiled edges we could fix that in a uh in Photoshop if we wanted to so now I'm going to go into my folder I've already downloaded some of these models I've got my this is my idle animation I've got a jump animation and a walk animation I'm going to drag the breathing guy on um okay he's not he's not got his textures with him so I'm going to do is click on the breathing I'm going to come down here uh there's the model um I don't think I change any anything there I'm going to go with an old style by the way animation type I'm going to choose Legacy because I know it works um if I come down here uh I'm I'm just press apply and we should be able to see him but he doesn't seem to be okay well oh I know why go on to animation um there we go we can see little movement so we know the files imported properly that's the important if you had made your earning blender and it didn't play there it means you've done something thing that it's not happy with okay so I've got the animation um I think that'll do for now now this is the bit it's called it says mix mode.com all of our animations are literally named mixo um and that's the data about it's actually what to do and we don't want to be called mix.com it's going to make our code very difficult to work with so I'm going to do is call this idle oh oh I don't want capitals I mean you can it doesn't make any difference whatsoever it's just my standard now I've done that I'm going to and make sure that I press apply if I don't press apply it doesn't make the name change so now when I click down here I can see the animations called idle I'm going to do the same again for jump um I'm going to go jump I'm on the rig again I want Legacy apply animation um change that to what's this this is like my jump uh again apply we should see there we go he's jumping on the spot that's fine it's throw me an error message I'm not going to worry about that right now I'll worry about that if it comes an actual problem um and finally I'm going to go to walking um yes I don't want to save that change did it actually save it yep it's called jump I forgot to press apply and save okay so walking again rig Legacy animation uh and this one is our walk cycle and again that forget to press apply on that last thing okay um no it's not changed it let's try again okay let me just open these up uh yep says walk says jump there we go that's all I need so we're not going to worry about these two now we're not actually going to use them on screen we're going to use the breathing but we're going to combine the animations okay um there's one more bit I want to do materials uh I'm not sure which one works I just know if I clicking these buttons it does so I'm going to click on materials import I'll go standard Legacy again uh I'm going to say use embedded yeah that should be fine extract I think no I didn't do that yesterday let me just try one more time let's see what happens okay there we go um yeah we'll just have fix now so now we've got um we've got our person that's now correctly textured and material etc etc okay so we got our character now if we were to press play um I'm not sure if he's going to play or not let have a look there we go we can see the ad animation is playing uh before I go any further I am going to move that camera in a little bit just because it's going to bug me being so far away if I track the camera let's turn our guy around a little bit so he's facing the camera there we go um and now to press play we can see that he should be animated now now what we want to be able to do obviously is use the other animations our idle to walking to Jumping so if I click on animations here there's our Idol I want to add the others I'm going to press plus and plus I've now got three animations to go at and if I click onto jump expand it with this little tick button find the jump animation drag it on can close that down open up walking um and drag the walk across okay so now they are named so what we can now do is write a script that's going to play these different animations so I shall come back into my assets folder I've already created a quick script called simpl move. CS if I open this up in Visual Studio it's currently empty that's not a problem so now we're going to start print some code in the first thing we need to do is create a variable called animation anim so that's going to create as a link for my code back to this animation of our guy obviously I should really rename him as well because calling him there go player oops that'll do nicely so now I've got player um I'm going to want to go again jump back in the code um so this is going to be a link to the animation just here uh but to link and get that I'm just going to grab a bit more code so these two lines animation equals get component animation going to so this is now full pulling all that from the inspector and I'm saying play the ID animation so if it wasn't playing the idle animation let's say you dragged um jump on there first we said jump idle walk it'll play whatever is in element zero first so this way if it wasn't if idle wasn't there it will play idle as soon as the program loads up I'm now going to come into update um for this yeah let's I'm just wondering how much to show you the moment I'll just cancel line out for the minute I'm just going to remove this one for the moment so I've got get key up Arrow play and again I don't have mio.com I've got walk so if I was just to save this file right now what I'm hoping to do is when I press the up Arrow they'll start playing the walk animation so let's just come back to Unity one player I can push get rid of that got far too many things open um we go I and drag this code onto player press press play and hopefully when I press the up Arrow we should start to go we should see the walk animation there we go walk animation now if I let go of go that go of up it's just going to keep on oh actually that's not too bad that's because I've not set it a loop normally normally when I do these animations um I actually set where is it normally I would set the animation to uh loop sorry not that one it's a loop so it would go on forever and ever but actually that might be useful now um and I'll leave that there for now so we can see what's happening the rest of the code so again if if I was to yes I want to save that so now when I press forward there we go he's now looping he's not looping forever oh well doesn't matter it's kind of working you can see it's going with it um it's probably I need to drag it back over the other other thing so I've got the player now what I want to do is um what I normally do is is if I had released the key so this is when you when you're pressing and holding the key in fact if you hold your mouse over it does tell you while the users holding the key down do this but what if you've let go of the key I'm saying if get key up I want to go back to playing the idle animation that's cuz normally the walk would be in a a forever Loop so that's how we can stop the animation well not stop it but go back to the idle one um now what if I want to press space if I press space bar to jump okay so I'm going to jump out animation did I press save I did not press save okay so now hopefully when I press play we should have got our walking there we go walking I'll let go of walking he goes back to Idol that's working quite nicely press space there we go we've got our nice little jump but he is going back to the first position of whatever the jump was so what we really need to do is now do some other code that checks to see where we're up to and go back to whatever our default animation is so if I just go if animation is not play in so there's another function built into Unity if anim is play in equals false this is a Boolean variable then just play the idol so while this is playing the whole jump until get to the last frame then it tells it's no longer updating so again I can go back press play and now going forward stop forward stop jump and there we go going back to it's not particularly smooth as we'd like it but it's okay for the time we've spent on it um Okay so we've now got our our three animations uh if I want to make him walk around that's what I can do now I'm going to bring in a new variable for our Direction so I just got some code I don't want to put in um so if I just bring a a variable so this is bad again this this is a local variable which means I'm declaring it over and over each time this Frame runs um and this is going to handle which way we're facing so it's a three so it's an XY Z for the direction you're facing in um I'm also just going to use again this is kind of bad I should change this um I've got this float velocity I'm prefixing with f for float velocity is setting to 1.2 I played about this number a little bit really this should be a global variable um that we could change depending on whether you're running or not but again that's something for you to maybe play about with um I've already got this line in place so our Direction the direction we're traveling is is the way it's facing forwards so hopefully um if we were to say click on our player movement the blue arrow should be the forward facing of the model now if you'd made yourself in blender and you'd model in the wrong direction it might go sideways instead um so I'm transforming the forward multiplied by our velocity times our Delta time so that's how much times passed between the last frame that run so if you slow computer or a flash computer it'll still be the same speed okay so that should move us well almost move us forward I need one more line of C to make it actually go forward which is now we need to transform it into the real world okay so this will now transform our Direction into our world space so again hopefully this should now make our character move so there we go got bit of forward movement and now there's still a few glitches in there um last couple bit occurred for now is going to be our turning so I'm just going to grab two Lin of code that I've previously written come across here so I've got my up up space uh and I'll just put my turn code there it doesn't matter where it goes I'm just saying if it's left Arrow right arrow I'm rotating around the Y AIS so the up and down axis and again you might want to change these numbers to turn faster or slower so hopefully we've now got a character that will move around a little bit again this is still not going to be super smooth animation there's still going be some issues but it all takes time and extra code and extra logic but I've now got a character that will walk around the screen still looks like he's slipping a little bit so I might just change that 1.2 now at the moment I can't hold forward and run as well so what I would suggest if you want to stop this video now go and play with this get your own animations do your own code uh if you want to stick around a little bit longer I'm going to do some more code so maybe make it a little bit more stable um which is involving the jumping again if you found this video useful please do like Please Subscribe positive comment below all the usual things um okay so I'm now going to edit this code a little bit more I want to make him jump U because at the moment if in in the code we I'll just put a collision box on him so I'm just going to close that animation down we don't need it anymore I'm going to add a box collide so let's look at box collider if I go to edit the Box collider cuz right now it's not solid it would fall through the floor if I turn some Physics on we can see this is down below his feet so I'm going to bring this up to about his shoulders not bother about a head test bring that to about his feet Oops about there come to the top view going to edit this down a little bit we do have to be careful now because he could fall over we can we can fix that if we need to so there we go that's his Collision box that's his hit detection so if you were to try and shoot him that's where would create a hit um now if I was to press play on this with the Box colliding view oops I'm going to turn that off so I can see it properly um free aspect where's it where's it gone I don't want to go big when I'm pressing play there we go I'm just going to take that to play Focus so it should not change when I press play so we can see we can see the box is moving with him but if I press jump the box is exactly where it is so if you try to jump over an object that box is still going to collide so what I'm going to do is actually go into more like Mario Super Mario Style jumping um so I'm going to go into the code we're going to add a few extra variables um this is my standard jump code I of quite some time I've got a Boolean variable so true or false are you on the ground so you can only jump if you're on the ground so no double jumping here this is my jump power so how high do you want to go the smaller the number the less impact the bigger the number the higher you're going to jump um are you currently jumping and then I'm also having a rigid body that's our physics thing um so I'm y I'll keep on going for the moment um I do need to access the physics thing so here again this is this is just reaching back to Unity so when I come back when you run the code it makes the code talk to whatever's here in the inspector um so now I'm going going to do the space bar to jump actually I'm going to do a couple of extra bits now I'm just saying is this working yeah this is fine this is fine um I'm doubling up Cod you see so I've already written some so I'm have another bit now I'm saying if you press space and you are on the ground so really this is this is going to ignore this one so I could probably get rid of this now um I'll be bad and I'll just comment it out I'm saying if you are on the ground and you press a space bar we still going to try and move forwards even though we've already moved forwards up here um and we're going to play the jump and we're also going to add a force this is like the physics engine giving you a boost up into the air uh which is the transform up uh times your jump power which obviously we did above Force mode. impul so it's a one single kind of blast um but what I'll also need now is to know if you're on the ground or not so I need two more functions which is the on collision enter and we also need on collision exit um and then I'll have to go back and make a few Chang in unit I'll that in a moment so we've got this is if we are on the ground then on ground equals true if we're not on the ground it's going to be fairly obvious we're false so if we are if we have left we are off the ground so this is going to keep care of whether we are on this is going to set basically this this variable just here which triggers this one just here so it's all kind of connected okay so I next change back into Unity it's going bit slow okay so back into Unity I need to do one thing now I need to make sure this is tagged with ground so I've just gone to add tag um ground is that what I called it yep that's fine um I need come click back on the ground again and make sure I have in fact added the ground so it's now T but I don't trust this mesh collider planes are only 2D objects I don't trust it so I'm going to get rid of it I'm going to add a box collide I'm going to just edit the collider itself I'm just going to which way is it going to go there we go I'm just giving it a little bit of depth um that should make it a little bit more robust for actually detecting it's because when I come back onto our player we're going to add a rigid body um so if if we didn't have this ground let's just say I tell this box collider off and I press play because I've now put a rigid body on our player is probably going to fall through there we go it's falling through the ground bring the plane back turn the box cladder back on he should stay where he is now there we go and when I press the space bar okay he's got a massive jump but you know you can play back with the numbers a little bit okay I'm going to probably leave it there for now because I think your next step is to is to experiment play with your animations get your own movements going maybe make him collide with different things and have a play with it that's the important bit I'll do another part of this video um in the future where I'll show you how we can go from blender to mixim Mo and back to blender and then back into unit so rather than having to import all of our animation separately we're just simply bring in one model from blender that has all these different animations built in um but that'll be in the near future again if you've got any you this video please do like please do subscribe positive comment below and of course maybe share it with friends okay and I shall see you in the next one
Info
Channel: lightsandclockwork
Views: 721
Rating: undefined out of 5
Keywords: VR, oculus, rift, quest, unity, development, c#, projectile, Lights and clockwork, quest 3, lesson, tutorial, setup, ovr, ovrcamerarig, virtual reality, Meta XR All-in-One SDK, AR, META, quest3, mixamo, animations, script, idle, walk, jump, physics, force.impulse
Id: LUHO367Fed4
Channel Id: undefined
Length: 21min 24sec (1284 seconds)
Published: Fri Jan 05 2024
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.