ANIMATE 2D CHARACTERS in Unity

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
in this video we'll have a look at how you can use unity snoot 2d animation tools to easily rig and animate your 2d character inside of unity the cool thing about this workflow compared to frame by frame animation is that it's extremely flexible and fast to work with since you don't have to leave the editor to create new animations you can do so on the fly such a prepared sprite for animation there are a few steps that we need to go through the first step is to create the bones that will make up our character will later use these bones to control our character when animating second step is to bind these bones to our sprite so that the sprite will stretch and Bend to follow our bones here generate some geometry around the sprite and define what parts of the geometry correspond to what bone the third step is to add iCade to our character like e stands for inverse kinematics and it's a way to make it easier to animate our character by adding game objects that act as targets which the character's limbs are trying to reach for this way we can simply move around these objects and the character's bones will follow the movement organically this way we don't have to individually adjust bones one by one also this video is sponsored by unity and with that let's animate our character so the first thing that we need to do is make sure that we have all the appropriate packages installed to do this we'll go window and open up the package manager and if go to the top here and view all the packages in our project we need to make sure that we have 2d animation to the I K and 2d PSD importer if any of these are missing we go to the top navigate to all packages find the missing package and hit install and that's pretty much all we need to do for setup now the character that I'm going to be using here is a PSP file PSP is a file format that Photoshop can save too and the cool thing about it is that when we import it into unity it will automatically separate your character into parts based on the Photoshop layers so for this character I've created six layers in Photoshop one for each arm and leg one for the body and one for the head and when we import it in unity we immediately see all of the individual parts for this to work we need to make sure to set the sprite mode to multiple and check character rig in the import settings if you want you can of course use regular PNG files instead you just need to make sure to layout each part of your character is side by side like you see here now inside of unity we can open up our character in this sprite editor to do that will select sprite editor and this is going to bring up a new window I'm just gonna grab this window and dock it by the scene view here in the sprite editor you can see how unity has chosen to separate our sprite if something is wrong here you can of course always go in and manually configure this but in this case it looks fine which means that we're now ready to start working with our character so let's go to the top left corner here and change from sprite editor to skinning editor and this is the window where we can prepare our character for animation and of course the first thing that we need to do is create bones so I'm gonna go to the left here and hit create bone and we now click anywhere on our sprite to start placing a bone and we can click again to create a new one I'm gonna create two for the chest here and continue one up through the head something like that and then gonna right click to stop the chain and of course we also want some bones for the arms and legs and we could make these completely independent but that would mean that whenever we move the base of our character our arms wouldn't follow and that's not really something that we'd like so instead let's select these bones and delete them and let's click the bone closest to our arms here in my case that's the yellow one in this center here you can now see that there's this transparent connection going from the yellow bone to the one that I'm about to create and that's because we're about to parent our arm to this bone so let's now create the bones for our arm here there we go and right click to stop with the same bone selected let's do the same for the left arm there we go and right click again we can now select the bottom bone here which will go to the legs and again for the other leg and right click to close that off so now we've created all the bones for our character and a really cool thing about this system is that we can easily see how these bones relate to each other to do that we'll hit re parent bone and we now get an overview of the hierarchy of all of our bones in other words which bones are parented to each other and to see this we can really just go through and select them so we can see at the very root here we have our first bone then we have our second bone and this goes into both our head and also continues on to the arms and at the bottom here we have our legs if we want to our bones we can simply drag them around to change their connections and we can see the UI updating to reflect that I'm gonna hit control set to undo if you want to create more bones for your character you can use the split bone tool and this is of course going to allow you to split a bone in half now once we're done creating the bones for our character we can hit preview pose and this will allow us to try and move around our bones if you click and drag at the root of a bone it's going to move the bone along with all bones parented to it and if you click and drag further down it's going to rotate the bone around its root of course you'll notice that this currently only moves our bones our character is completely unaffected that's because we still have to skin our character in order to make him understand what bones correspond to what part of the sprite will do that in a sec for now we can hit reset pose to reset all of our bones and I just want to show you that if we rotate this yellow bone we can see that the arms rotate with it again because they are parented to this yellow bone and because the red bone here is at the very top of the hierarchy in other words this is our root bone if we move or rotate this all of the other bones are going to follow so let's now reset our pose and let's start generating some geometry for our character to do that we can hit Auto geometry and for now let's just leave the default settings and hit generate all sprites and as you can see this immediately creates this mesh like structure around our character you can also see that it's added a bunch of colors corresponding to each of the individual bones so the first thing that it's doing here is generating the mesh and the settings here will help you define the detail of this mesh so the greater the outline detail the more points will be created along the edge of your character so if we increase this to a very large number we can see that it's creating a bunch of points I find that it's often fine to leave this at a fairly low number subdivide is going to do the same thing but inside the sprite so it's basically just going to fill in more vertices if we increase this we can see that happening again I'm just going to leave this at the default if you find that some place of your model is generating in a weird way or if you just want to get really detailed you can go in and edit the geometry manually to do this we need to first double-click on the sprite that we would like to edit for example if we'd like to edit the head here I'll double click on it and we can now go in and change around points as we wish if we want to create another vertex we can hit create vertex and simply slap it on there you can also create edges split edges and I think you get the idea now once we've created some geometry for our model that we're satisfied with it's time to create the skin weights for our bones now before when we Auto generated our geometry it actually went ahead and did this automatically and that's because weights was checked off if you accidentally generated this sprite with out weights you can always go under Auto weights and hit generate and we can see that by default it actually does a fairly good job the head here is mostly influenced by the green bone the bottom of the left arm is mostly influenced by the orange bone the bottom of the torso is mostly influenced by the red bone and so on and we can actually now preview what this looks like when we start to move around bones to do that let's hit preview pose and let's just try to change around some bones here you can see that the arm is actually modifying quite nicely however once we start to get to the shoulder it does a bit of weird stretching if we move our head we can actually see that it looks fairly nice however it might change up this shoulder is a bit too much the torso also bends fairly well as does the right arm but again we might have a problem with the shoulder and the legs work pretty well as well now to manually edit this we have a few tools one that I found works really well is the possibility to change bone influences if we click on the bone influence button and select a sprite let's for example select the head here we can choose what bones will affect this particular sprite so in the case of the head here I would actually like it if only the green bone affected the head not the yellow one so I'm gonna select the yellow bone here and remove it from the list if we select the torso we can see that quite a few bones are currently affecting it I think it would be great if our arms and legs didn't distort the torso so I'm just gonna select each of these bones and remove them now this might cause some really weird stretching at first but that's because we need to regenerate the weights after doing this until then we can just hit reset pose let's also double-click our arms this looks good it's only affected by the arm bones the same thing with the right arm the legs are also generated nicely so that's pretty much all we need to do so if we now go to Auto weights and regenerate it's going to create the weights based these bone influences so if we now go to preview pose and try moving around our arms we can see that the torso is completely untouched we also see the same thing happens when we try and move our legs and when bending the torso nothing happens to our head our head still influences the torso a little bit I think it actually does that a bit too much and this is where we can go in and actually change the weights themselves to do that we have two tools we can either use weight slider this allows us to double click on a sprite in our case let's choose the torso we can then select a bone I mean then increase or decrease the influence that this bone has using this slider so if I pull it down we will see that our head now has less influence on the torso now I might have overdone that a tiny bit it's now only changing this part of the body so to change that we can go in with a weight brush and here again I'm double clicking on a sprite I'm choosing a bone that I want to paint with we can choose the hardness as well as the size of the brush and we can then go in and paint onto the individual vertices how much we want this bone to affect them so now if we go back to previewing the pose we can see that we might have overdone that a bit but you get the idea we can just as well go back and by holding down ctrl and painting we can remove influence as well so once you're satisfied and you've tried playing around with the preview pose and aren't seeing any weird stretching in your sprite we can hit reset pose and we are now ready to add it to our scene so let's take the sprite editor and our get to the right here and this step is actually ridiculously easy all we need to do is hit apply and we can then take our character and drag it in to our scene that's it that's actually all we need to do we can now see that inside of this object we have all the individual sprites as well as our bone hierarchy where we can go through and view each individual bone and inside of our scene view we can of course click and drag on these in any way that we would like to so you can see just how easy it is to really set up a character and start animating and the way that this is working is that for each sprite unity has gone ahead and created a sprite skin component and each one of these references of the bones that have control over this sprite so for our body here that's bone 1 2 & 3 which is these three bones and if you ever want to go back to the default pose you can always hit reset bind pose for each one of these sprites finally we can of course add a case to our character in order to make him easier to animate first we need to select the base object well then hit add component and we'll search for I K manager and select I can manager 2d this script is not responsible for I key on our entire character for this character I think it would make sense to use I cave for the arms as well as the legs to make it really easy to control these parts so to do that we need to add four i case solvers and our case solver is responsible for doing all the calculations necessary on a particular part of our character to add an eye case solver we can hit the plus sign and here we get three different types to choose from which type you want to use depends on your situation limp is the standard to burn solver and this is ideal for posting joints such as arms and legs which is what we want to do in our case the other two chained fabric and chained CCD are basically solvers that can be used when you have more than two bones in a sequence the difference between fabric and CCD is what algorithm is being used to calculate the position and rotation of the bones if you want to learn more about the differences between the three solvers I will of course have a link to some documentation in the description now let's go ahead and select limb this is going to create a new limb solver 2d let's just rename this to left arm solver and any solver needs a target so let's go ahead and create one in the case of our arm here we can go ahead and create a new empty game object under bone seven which is our button most arm bone I'm gonna call this left arm target and I'm just gonna take my transform tool and move this to the end of the arm then we can select the left arm solver and drag in the target we can see that the target now shows up with this yellow dot here and if we now hit create effector we can see that both our target as well as our bones turn green that's because the limb solver is currently acting on these bones so if we go ahead and drag on our target we can see that the bones will automatically update to follow around this target now where did the effector go well this was actually generated under the left arm solver and it's called left arm solver underscore affector so now we simply need to repeat this process for the other arm as well as the two legs all right so we now have for our case solvers each one of them is a limb solver and each one of them has a reference to a target that is placed at the end of that bone chain which means that we can now very easily animate our character using these IKEA handles we will also see that our legs are currently behaving in a pretty weird way the reason for this is that when we're dealing with a limb solver we sometimes need to flip the direction of the I K in order for it to face the correct direction so now our character is really easy to animate and that's exactly what we're gonna do let's go to window animation and let's open up the animation window you can also hit control 6 to do this let's target at the bottom here let's select our cup and it's create a new animation I'm just gonna call this animation party let's it save and let's hit the red button to record and we can now animate our characters so I'm gonna start him off here and here here and here and it's also animate the head here there we go and let's move forward a few frames and let's change around the eye key handles and let's try and preview this animation we can maybe zoom out a bit and let's actually move these keyframes over let's duplicate the first ones and let's try and hit play there we go we've created our first skeletal animation awesome that's pretty much it for this video from here it's up to you to start making animations for your game if you want to see more about the new 2d tools there will be some links for the documentation as well as the example character in the description if you liked this video and want to see more make sure to subscribe so you don't miss a future one also make sure to ring the tiny notification bill to get notified when a new video comes out on that thanks for watching and I will see you in the next video thanks of the awesome patreon supporters who donated in October and especial thanks to Andrew kononenko art Arman true VR systems simmer io X and a player cheetah 3d Jeff Johnson infinity PBR Sybok mami Dennis Sullivan Chris Sheriff Abdullah prism fi thanks so long clear the set Vincent and skewer shreya ste Turkey's Kirk Ronan Tim Apple debauch Bruins cat Noah Kiyosaki Gregory Pierce Larry tweet James Rogers Rob parent pecan Vania Erasmus Robert pond Kerr Jackson James P Anthony Patton Q sweet is key and a breeze see you guys Rock
Info
Channel: Brackeys
Views: 730,760
Rating: 4.9479804 out of 5
Keywords: brackeys, unity, unity3d, texture, textures, material, materials, beginner, easy, how, to, howto, learn, course, series, tutorial, tutorials, tip, game, development, develop, games, programming, basic, basics, 2D, 2D animation, animation, skeletal, skeletal animation, IK, IK manager, rig, animate, rigging, weight, painting, bone, bones, anima, animator, key framing
Id: eXIuizGzY2A
Channel Id: undefined
Length: 15min 40sec (940 seconds)
Published: Sun Nov 25 2018
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.