2D Character Rigging and; Inverse Kinematics - Unity Tutorial
Rig up your 2D character in Unity using Unity's 2D animation library (creating a skeleton). Next, I'll show you how to hook up IK (inverse kinematics) to your character to perform realistic joint movements. Finally, I'll show you how to use all of this together to create great-looking animations.
Note: The photoshop steps can be completely replaced by your software of choice. Instead of using PSD Importer, simply import a sprite with the components laid out side by side.
PSB file: https://bit.ly/3DQjrnd
in this video i'll show you how to set up a skeleton for your 2d character and then animate it using inverse kinematics step 1 lay out your character in photoshop ensuring you have a different object for the legs arms torso and head also ensure the layer order is how you would like it to reflect inside unity when you're happy with your creation go to file save as find the project that you would like to import it into and save it as a psb file step two in unity go to windows package manager and ensure 2d animation and 2d psd importer have been installed step 3 find your psp that you imported click sprite editor and drop it down to skinning editor this is where we will be rigging our character step 4 click create bone and then starting from the bottom of the torso begin creating the spine up to the head of your character you can right click to end the chain to do the limbs click the pivot of the closest bone to create a parented chain so i'm going to create the top of the leg the bottom of the leg and then the foot i'll do the same for the back leg now that i have those mapped out i can tidy them up a bit by clicking edit bone and then bringing the pivots down to where they should be like that i'm now going to do the same thing for my arms using the middle torso bone and i'll tidy those up and now your skeleton is complete to make your life easier while animating and manipulating ik you can click on a bone and rename it for example i'll call this one spine1 this one spine2 this one head and so on once you're done click apply to save your changes step five now that we've sorted out our skeleton we need to assign what geometry is controlled by each specific bone an easy way to do that is to click audio geometry and generate for all visible now mesh will be following the bone but as you can see it's not perfect for example this torso is being affected by this arm here and that's undesirable for me so to fix this i'm going to double click the torso mesh i'm going to click bone influence and then i'm going to unassign the bones which i would not like to affect this mesh for example i don't want the head to affect it i would not like either of the arms or the leg and then click the minus button here now you'll notice the torso is not affected by the arm mesh or the leg mesh to reset the pose simply click this reset pose button you should now be able to pull your psp directly onto the scene and manipulate the bones the way you'd like if we inspect our new object we will see newly created bone hierarchy as well as sprite renderers with the correct order layering depending on your photoshop import to avoid manipulating the original psp file let's right click it create prefab variant let's call this avatar this is the object we will use going forward step six to add ik to our rig click the root object add component ik manager 2d here you will see a list of your current solvers to which we have none to begin click the plus button and select lim here this will create a new limb solver for you i'm going to call this front um solver next we need to create the effector of the limb so i'm going to go to my arm and on the last bone of my arm i'm going to create an empty game object and call this effector i'm going to put this to the end of my bone select my solder pull my effector into the effector slot and then click create target this will create a new target underneath your solver you can grab this target and now move the arm around using ik i'm going to now do this for my remaining limbs go back to your ik manager and click new limb this will be my back um solver i now go to my back arm bone create an effector remember to slide the effector down to the end of the bone slot in the effector create target and you'll notice with this bone it is bending the wrong way in a very painful way so what you can do is you can click your new solver and click the flip checkbox let's do the same for the legs now for the legs i don't want him to be walking on his tippy toes so i'm going to be using the bottom the ball of the foot joint here as the uh affected joint so lower back leg create the effector make sure you slide the effector down to the end of the bone great target let's do it for the other leg and there we go with the limbs done we can now move them all around and affect him in a realistic manner if you want to reset the pose of your character click the ik manager and restore default pose as you can see the hierarchy can get pretty confusing what i like to do is create an empty game object and call it my solvers and i will grab all of my solvers and place within and as these do not need a parent child relationship i will then grab my targets and then place them outside of the group next you'll notice now that if you move your torso your arm targets don't move with it so i grab my arm targets and then let's make them a child of the spine and be sure to override the changes you've made so far on this prefab variant step 7 it's time to animate click window animation and open the animation tab and dock it and let's also open the animator tab and dock it down there as well to begin animating select your avatar and click record now you can begin manipulating the bones to fit your animation remembering that the limbs themselves should only be changed using the targets whereas the torso in the head can be directly manipulated by the bone because i set my ik to only use the two top ends of the leg i can directly change my feet position next move fold a little bit in the time frame and change the bones a little bit to perfectly loop your animation you can highlight all your first keyframes ctrl c to copy go to where you'd like your animation to end ctrl v and then press spacebar to try it out if you learned something consider subscribing to the channel in the next video i'll show you how you can convert this into a rag doll when the player dies you