Using IK to Improve Animations in Unity

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
[Music] as a solo developer with limited time and resources i often look towards asset libraries to fill my needs for character animations and if you've ever retargeted an animation in unity you'll know that using them often comes with their quirks inverse kinematic rigs help us to fine-tune animations so that we can create more advanced variations of movement or just help us more easily correct some of the quirks of baked animation data even teams of developers with dedicated animators and artists make use of ik tech in fact if you're watching this video you've probably already seen lots of talks or lots of write-ups about the technical process of procedural animation and custom ik chains from various colleagues in the industry and while you may think that ik is just good for things like programmatically moving a creature's legs or managing realistic operation of an industrial crane there's some far more close to home use cases that all developers can utilize whether you're a solo developer or huge team sometimes you've just got to put your hands on things hi there i'm matt and welcome to gamedev guide in this video we're going to take a look at how we can utilize ik in our games to level up our animations in unity we're going to start by taking a look at how an ik rig works by correcting a character's idle animation we're then going to look at how we can use ik to have our characters look at points of interest dynamically and finally we'll take a look at how we can create ik tracks in timeline to have more control over animations during a cut scene so let's jump into it i have a small adventure game prototype that i'm working on here currently i can move around the apartment with my mouse and keyboard we have a few points of interest scattered around and over here we have a mailman who is ready to deliver us a letter now it's out of scope for this video so i'm not going to be covering it but if you're interested in how i put this scene and the character controller together stay tuned to the end of the video for more info on that as you can see here our mailman is using the same idle animation as our main guy but because of the bag his arm is clipping through so we have a couple of choices we could manually go in and edit this animation to account for the bag or we could hire someone to create a new animation specifically for our mailman both of these are pretty expensive and time consuming so instead we're going to use an ik rig to adjust our mailman's hand and account for the bag keeping the rest of the animations intact now before we get started with that i just want to note that i'm going to be using components from the final ik asset store package for the video however you can also achieve similar results with unity's new animation rigging package i've chosen to use final ik because i'm most experienced with it and generally prefer its feature set the animation rigging package is pretty powerful but it's a lot more generic focusing on larger applications of ik whereas final ik has a lot of powerful bespoke components specifically for humanoid rigging alright with that out of the way let's start by exploring how tools like final ik work and make some corrections to our friendly mailman over here the first thing we want to do is add a full body biped ik component to our mailman once added it should use the avatar on the animator for the character to find all of the bones it'll need if you're working with a generic rig you may need to set these references up manually we want our mailman's left hand to be placed on top of his bag here so we're going to create an ik target for the left arm let's create three new child objects and assign them into our left arm targets unfortunately ik only works in play mode so we'll need to start the game up before we can adjust the settings any further in our component let's increase the position weight of our hand as we increase the weight notice how the body is magnetized towards our target transform this is ik in action in order to reach this low point the rest of the bones need to move and rotate to match the character's hand in this position i'm sure you can already see how this can be a great way to fine tune your animations by sliding the weight back and forth we can make it look like our mailman has bent down to pick up a letter he dropped from his bag let's make some adjustments here and get his hand on his bag the trick here is to play around with the position and rotation weights until you get something that looks good the further the weight is below one the more the bones are influenced by the animation and vice versa so in my opinion it always looks better to keep the weight somewhere in the middle and push the effector a bit further if you get some funky things going on with the elbow you can use the bend goal target and weights to position it into something that looks good now it looks like he's resting his arm on the back now we're in play mode and we've made quite a few changes so the easiest thing to do is to copy our mailman here exit play mode paste him into the scene and then we can copy our values back over to our main instance now our mailman is fixed and we know a little bit more about how ik works one of the things i'd really like to do here is have our main character look at specific points of interest in the scene as he walks past or stands nearby them we can do this by using ik to twist and adjust the head towards a look at target let's add a look at ik component to our character and then hook up its corresponding transforms and add a look target transform now if we hit play our character will be staring at the ground if we move the target around he'll twist and turn to keep looking at it different models and setups will yield different results so it's worth playing around with the different clamp settings here to get something you're happy with i've put together this component that will search for nearby points of interest each point of interest is just a simple target volume and if our character is inside one of these it will move the look target to the point of interest position if there's nothing nearby it'll just move the target in front of our character instead as you can see this adds so much more life into our character as we move around the scene our player character looks towards these points of interest it's a great way to clue players into things they can interact with and just adds an extra level of polish to your gameplay similarly this kind of behavior is incredibly useful to add life into npcs as well i've copied over the code here and made a few adjustments for our npc now when our player is nearby our npc looks and reacts to them moving around so now that we have a basic grasp of ik we can move on to something a bit more complex and really level up our animations it's not uncommon to want to animate our characters to do things in our games however we don't always have to resort to complex animations for that task we can use ik in our animations to manipulate a single animation clip into a more complex state to demonstrate this let's look at how we can use timeline to combine animation clips and our ik controls for a cut scene i've put together a little shot here in timeline for whatever reason our character needs to pick up the plant i've just got the idol animation and based on everything we know so far instead of using a bespoke animation we can use ik to blend from this idle state and have our character reach to pick up the plants so what i'm actually going to do is use a custom ik track to blend between different target points i've already gone over the process of creating custom tracks and mixers for timeline in a previous video so i won't be going into too much detail here i'll link the video below in case you want a more detailed breakdown about extending timeline tracks so we're going to create two sets of extension tracks a full biped ik track and a lookout ik track these will target their corresponding components on our character both are very similar in structure so i'll just go over them quickly the clips for each track type have an exposed transform for our positional target and a weight goal for the target our body ik clip has a couple of additional properties for both rotation and bends these are then stored in the corresponding behavior class the key reason for using a custom track for rik is so that we can blend between different targets which means that most of the logic will take place using track mixes so our track asset itself is pretty standard however in the body ik track i've designed the ability to set a specific reference part of the body this just helps for organization as i find it much easier to have a different track set up for the left hand right hand leg or body the mixers themselves are very similar in both mixes i'm simply collecting each of the clips and then blending the targets together for a final position and weight the body ik logic is doing a little bit more to account for the bend goals but overall they're both pretty straightforward [Music] this then gives us two sets of tracks to work with let's start with adding our look track the cool thing about doing it this way is that we can use multiple transforms in the scene as our targets so we can have our character look from off camera and then blend towards the plant we can also make use of the mixing to control the speed of the change and because we're luping between the two we can also adjust the curve here to change the motion slightly too next i want our guy here to lean in and grab the plant so let's create a new body ik track and a grab target as i mentioned before each track is set to target a different effector so let's make sure that the hand is set as the target for this track [Music] if we preview our timeline our character's hand snaps into place we can use the transition settings on our clip to blend the weight on our character's hand and have them reach over to the plant and grab it and this is the gist of it really from this point we can play around and combine different transforms clips and weight settings to get additional behaviors out of our character without the use of any additional bespoke animations if you really wanted to go the extra mile you could potentially animate the affected transforms themselves and have them move alongside the weight values to get even more fine-tuned behaviors but for a quick pick-up insert for an adventure game i think this would get by obviously there's a lot more you could do to fine-tune things here and it's probably not worth throwing everything you know about animators and state machines out of the window and replace it with ik but relying on a combination of different animations and supplementing their states with ik for more advanced behaviors is probably the ideal scenario and that's about it for today hopefully from this video you've been able to see the power of inverse kinematics and some of the things you can do with it as usual i feel like i've barely scratched the surface here but if you enjoyed the video be sure to give it a thumbs up also i'm curious to learn about some of the things you lot are working on and some of the ways in which you're making use of tools like final ik or the animation rigging package so if you are be sure to leave a comment in the description down below speaking of curious i'd like to take a moment to thank this video sponsor skillshare as you know skillshare is an online learning community with thousands of inspiring classes for creators where you can explore new skills deepen existing passions and get lost in creativity and because it's a platform specifically curated for learning there are no ads and they're always adding new premium classes so you can stay focused and follow wherever your creativity takes you if you want to spend some time learning a bit more about animation there's some great classes available one of the classes i've been interested in is this one on simple character animation by fraser davidson he teaches you how to start by designing a model in illustrator and then takes you through the process of building and animating it in after effects i can see tons of potential here as this class can be really helpful if you're looking to create and animate 2d characters for your game so if you're interested in skillshare and you want to help support the channel the first 1000 of you to click the link in the description below will get access to a free trial of skillshare's premium membership so you can explore your creativity and check out some of these classes for yourself as i mentioned at the start of the video if you want to learn more about how i put this demo scene together and how i created the character controller i've released a short unscripted behind-the-scenes video exclusive to patrons and i'll be answering questions on the patreon discord channel so follow the link below or on screen shortly to join the patreon and get access to that additionally if you're new to the channel please do consider hitting that subscribe button as it helps the channel out and you'll know when new videos go live if you're interested in more from me why not check out one of the new videos on screen now as always thank you very much for watching and i'll see you again next [Music] time
Info
Channel: Game Dev Guide
Views: 53,025
Rating: undefined out of 5
Keywords: unity, learn, games, gamedev, how to, making games in unity, tutorial, unity tutorial, learning unity, unity3d tutorial, programming, making games
Id: UD6URb8aCco
Channel Id: undefined
Length: 12min 5sec (725 seconds)
Published: Tue Jun 29 2021
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.