Make your Characters Interactive! - Animation Rigging in Unity

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
after we're making a game you need your characters to interact with things around them sometimes they need to pick up objects sometimes they need to aim in the right direction and sometimes they just need to place their hands and feet correctly on the environment this used to be a pretty complicated task but luckily unity has added a feature called animation rigging that makes it so much easier it's currently in preview but most of the big features have already been implemented but Before we jump into unity and start using it let's have a look at how animation rigging works also this video is sponsored by unity so normally when we have an animated character in unity it consists of a few things a base object with an animated component this controls what animations to play as a child of this object is the mesh itself this normally has a skinned mesh renderer component and is responsible for rendering the character itself and finally we have the character skeleton often called the rig this is a hierarchy of game objects that make up the individual bones of our character for example this character has a pelvis bone that leads to the spine that leads to the thighs that leads to the calf and then the foot so character animation basically works in three steps the character plays on animation determined by the animator the bones are then moved around by that animation and the mesh of the character then shapes itself to follow the bones using the skin mesh renderer but what if we don't know beforehand exactly where we want opponents to go animations are fixed so they don't always fit perfectly with the interactive parts of our game say for example we want a character to look towards the player well in this case we need to change the rotation of the head while the game is running depending on the position of the player but we can't do that if an animation is already controlling our head bone this is where animation rigging comes in with animation rigging we basically create an extra rig on top of the original one that then overrides part of that animation think of this like a much simpler rig which only has two controls that we need in this case we would create a rig with the multi aim constraint this component would reference the bone that we want to control in this case the head bone as well as a new object that we create to act as the target when we then play we can see that our original animation plays just fine but our head rotation is being controlled by the new rig this allows us to do many things just using different kinds of constraints it when it comes to the character interacting with objects so with that explanation let's jump into unity and try it out some community and as you can see I'm using version 20 28.1 animation rigging will also work with 20193 but unity have added some nice convenience features to make setup easier in the new version and the first thing that we wanted to do is go ahead and install the animation rigging package but it's currently in preview so first we have to make sure to enable preview packages to do this we go under edit go to the project settings go under package manager and make sure to check enable preview packages with that we can simply open up the package manager window so I go window package manager here at the top we'll make sure to show all packages and now we can just search for animation and here is the animation rigging package let's simply select that and install it and that's it the package is now ready to be used now as you can see I've gone ahead and set up this very simple example scene with just a camera ground and a character and with all the talk of bones I thought that nothing would be more appropriate than an actual skeleton the skeleton character here is freely available on the asset store will of course have a link for that in the description now this character has an animator here that if we hit play just place the idle animation over and over we can see that inside of the animator window but remember we could be playing any kind of animation and we can easily switch between them while overriding some of this movement but we'll see that later now the first thing that I recommend you do is setup animation rigging to show some of the bones that are making up our character and we can actually do this really easily by simply selecting our character going animation rigging and selecting bone renderer setup as you can see this adds a component that references all of the transforms that make up our rig this is a rig here and these are all the different bones inside of that rig and as you can see they're all reference here and it simply displays them inside of the scene view we can go ahead and change the size of the bones the color and the shape but for now the default settings are going to do just fine and this is not only going to show the bones it's also going to allow us to select them using our mouse which is just really handy now the second thing that we're gonna do is create a rig remember animation rigging works by creating an extra rig on top of our original one that is going to modify our movement to do that again we just select our character we go animation rigging and hit rig setup and as you can see that creates another component this is the rig builder which now has a rig layer called rig one and if we click that we can see that this is an object that is now under our character called rig one with a simple rig component so this is where we're going to be building our rig in other words we are going to be adding constraints under this object if example we wanted the head of our character to be constantly looking at a target we could go ahead and add a multi aim constraint so I'm gonna right click on this object here and create a new empty object under it I'm gonna rename this object to head aim and I'm gonna go ahead and add a component here go into animation rigging and here we can see all the different constraints I'm gonna select multi aim constraint now here we need to fill out a few things the first one is the constraint object this is what we want our constrain to apply to in our case that's the head since we want to be controlling the head with this component so I'm gonna go under our skeleton here and I'm gonna go ahead and find the head and drag that in then we have the aim axis in our case that is going to be the y-axis and finally we have the source objects in other words the target that we're going to be aiming towards you can create multiple targets here and blend between them for now I'm just gonna go ahead and create one target so let's go under our hit aim here that's right click and create a new object let's again rename this object I'm gonna call it target and instead of having this just be invisible inside of the editor let's go ahead and add a gizmo so we can do that down here in the right hand corner we can hit the plus sign and this allows us to choose an effector gizmo so first under the shape here we can search for effector and as you can see there are some different ones there's a ball a cube a circle a locator and a square I'm gonna choose the ball effector for this one I'm also going to set the size to something like point two and now we can clearly see the target then we can go back to our head aim and simply assign this target as a source object and it should actually work now but under these settings we have the possibility to limit how much our head can rotate which is probably something we want to do because there is after all a limit to how far we can stretch our neck it might not apply to this skirt and guy right here but it's probably still going to look better if we added so under the minimum limit here I'm gonna put in minus 100 and as the maximum limit I'm gonna put in 100 so now we can only rotate 100 degrees in either direction and that's it if we now go ahead and play we can see that our head immediately snaps to look at the target and if I now change this target around as you can see our head just follows awesome and we could of course put this target anywhere we'd like we can have it follow around a player character we could place it if something important is happening say an explosion happens over here we probably want the characters to notice we can do so much with this stuff and as you can see it works perfectly as long as we don't get too far behind the character next really aren't made to stretch this far and it does lead to some weird behavior so for this I would recommend adding some kind of script that reduces this effect if the target gets behind the character look at the under the rig here there is a weight this allows us to control how much this constraint should influence our character so if I go ahead and dial that down we can see that our head is no longer being influenced by the weight so what you could do is simply reduce this using a bit of code if the target gets too far behind the character so weights make it really easy to control when to apply constraints and we can actually control the weight of individual source objects as well if we select the head aim there is a weight slider here under the source objects also right now for example it looks a bit weird because only the head of our character is rotating normally humanoid characters will rotate a bit of their chest and arms as well so let's quickly add that using the weight slider to do this we can simply select our head aim and duplicate it so I'm gonna press control D we can then rename this to chest aim and instead of having a separate target for this that's delete that let's take our target here and move it outside of these two so it's a separate object and let's also assign that to our chest so now both are heading and chest aim are using the same target and what we can simply do is go into our chest aim and reduce the weight so I'm gonna put that down to something like point three and instead of constraining the head here let's go ahead and constrain the spine so I'm going to take the spine one and drag that in instead so now we have two multi aim constraints affecting two different parts of the body with eight different weight and that means that if we play and move around our target we can see that our entire body is now rotating a bit towards that target which makes the movement seem a lot more natural awesome and remember how I talked about that we could apply any kind of animation well if I go in to the animator now on this character and change to a walk animation it just works really cool now there of course many more constraints that we can apply to achieve different results one that I use a lot is the two bone I constrict this will allow us to have the arms and legs of our character probably bend to follow a target so you can just imagine how useful that is let's try to set up one for the right arm and we could of course add this inside of the same rig but since we're affecting a completely different part of the body let's go ahead and create a separate one so we'll select our character look under animation rigging and let's again press rig setup as you can see this adds a not the rig layer to our rig builder and again and not the object and maybe we could rename these two to something other than rig one and two let's have the first one be head rig and the second one be arm rig then inside of the arm rig we can right-click and create an empty object let's rename this one to arm mover let's set a component corner animation rigging and select lead to bone ika constraint now as you can see this text in three bones instead of just one that's because it will apply some natural movement so natural bending of the bones as long as we have three bones in sequence so in our case we need the route mid tip to be the bones that make up our arm let's go under our spine here under the neck let's find our left arm here we have the upper arm then the forearm and then the hand so let's start with the hand here and assign that to the tip we're going to assign the forearm to the mid and the upper arm to the root of course we also need a source object as you can see the target is currently none so let's go under our arm rig and arm mover here let's right click and create another empty object let's rename this one to target and as you can see our target is currently placed down here instead we want this to be placed on the hand because we are going to be moving around our hand and arm with this object so to snap it to our hand we can simply select the target then hold down control and select the hand then go under animation rigging and hit a line transform and as you can see the target immediately snaps to our hand we also want to display this with a gizmo so let's go to the bottom right corner and hit plus again we can choose an effector shape I'm going to search for effector I'm gonna choose the square root vector I'm gonna set the size of this to something like point three and there we go we now have a square here that we can select and move around and finally let's go to the arm mover and assign this target and that's it if we now hit play we can see that while our character is playing an animation our hand is now remaining in place and that means that we can actually select this target object here and move around our hand even rotate it in any way that we'd like and our arm will appropriately follow really really cool and a cool tip is actually to move the target while the game is running to somewhere you think looks cool like here and then just copying the placement by right-clicking on the transform and selecting copy weld placement we can then stop playing and go to the target right click on the transform and hit paste world placement so if we hit play indeed the arm goes right up and we can use this for all kinds of things like placing the hands correctly when holding a weapon now in our case this is what we want but sometimes we don't want the hand to snap to the target sometimes we want to just keep that offset and in that case we can go under the arm mover go settings and under maintain target offset we can choose whether to do that on position rotation or both just something that's good to know there and again we can adjust this using the weight slider imagine for example that all the skeletons are gathering and they want to check if everyone is present John are you there of course you can change the weight and position through script you can change it through the animation window and everything even works with timeline now as well so you can just imagine the possibilities and the good thing is that animation rigging runs on jobs so it's very performant one thing to note is that because it runs on jobs you shouldn't reassign targets while the game is running so if you need to change between following different objects I would recommend creating a script that just moves the target to the right object and of course from here it's up to you to start playing around with adding different constraints as you can see there are a lot to choose from luckily they're all really well documented well of course have a link to where you can learn more about them in the description another thing that is good to know is that multiple constraints within a single rig applied based on their order in the hierarchy so if you're working with multiple constraints in one rig the top one will be applied first in our case here that's the heading and then the chess team gets applied the order of the rigs however are based on the order of the rig layers in the rig builder so under a rig builder component in our character here we can change the order of individual rigs and if you need some good examples on how to use some of these constraints you can simply go to the package in the package manager and here we can look under samples let's import these and this will create a unity folder here with some constrained samples and if we open up the scenes folder we can see that there are lots of examples for the different ones of course if you're using Europe Eli key you might have to update some of the materials we can do that by going edit render pipeline Universal render pipeline upgrade project materials to universal and hit proceed and then everything should show up and as you can see here's an example of two bonide k one of the multi aim one for blending one for I K on an entire chain of bones one for parenting if you want to have objects follow your and the list pretty much goes on as you can see it can get pretty crazy awesome and that's pretty much it for this video if you enjoyed it make sure to subscribe and ring the notification bells so don't miss the next one well of course that links to where you can learn more about animation rigging in the description including a TDC talk on some more advanced use cases on that thanks for watching and I will see you in the next video thanks to all the awesome patreon supporters who donated in May and especially thanks to face Samara fire lost to violence locked forever replica studios na'vi ninja SOT Mike Jason Narita SKU Luna set piano satin black Donna team Cascone 10 - Sam Jacob Sanford no he was sake mug and 20 rod Gregory Pierce Michael Cobb of the mighty Zeus Owen Cooper as in the Pierce Erasmus and serious mode you guys Rock
Info
Channel: Brackeys
Views: 834,134
Rating: undefined out of 5
Keywords: brackeys, unity, unity3d, asset, assets, easy, to, howto, learn, tutorial, tutorials, game, development, develop, games, programming, coding, C#, how, beginner, animation, animation rigging, rigging, character, procedural, dynamic, head, follow, aim, ik, inverse, kinematics, two-bone, bone, bones, skeleton, rig, move, place, feet, look at, interact, environment
Id: Htl7ysv10Qs
Channel Id: undefined
Length: 16min 19sec (979 seconds)
Published: Sun Jun 21 2020
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.