[#07] Unity Animation Rigging: Keyframing Rig Constraints to create weapon animations

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
kyouda welcome back on the Kiwi Koda and in this video I'm gonna show you how to animate rig constraints to create these weapon animations here so I have a character that can host a whole storage pistol and if I walk over the assault rifle then there is also a separate animation for animating the assault rifle cool let's get started okay so this video follows on from a previous video of made their weapon pickups equipping weapons at runtime so in the scene here I've got a character that's holding a pistol and the position of the pivot node the lift in the right note they're currently being keyed in with a single single keyframe on this weapon animation pistol clip and what I'd like to do is basically create a animation where the character holsters the weapon onto their leg but the problem I'm having at the moment is if I hit record characters or starts like sliding around and doing weird stuff and the reason for that from what I've found is the character setup that I'm using and this main characters if BX file the animation type is set to humanoid also the same on the locomotion animations they're all humanoid humanoid animations which unity does not allow you to keyframe humanoid characters which is a bit of a bummer so if you're using like let me just go show that drop down again if you're using on generic animation type then you won't actually have this issue it will actually be fine you can keyframe generic animations fine it's only the humanoid ones that have issues so I've had to find a workaround for this and yeah I'll show you what I've done I haven't run into any issues yet but yeah I guess it may not be the most standard way to do it but what I've done is create a new rig controller and then attach a animator to the rig layers and then attach a rig controller basically inside as it's a child of the main character animator now and what happens is if I open up this rig controller and let me just assign like this clip for example okay that's not great one yeah I can just delete all these keyframes actually we'll just reoffer this so inside the scene view now if I select that in an animator and press record the character doesn't go AWOL it's actually a it's actually fine and the main idle animation is still playing back but I can at the same time I can record and start keyframe means some of these these rig constraints which is yeah really really cool okay so just need to clean up some stuff really quickly so inside the main animator the third person shooter I'm just gonna delete this with and lamp because all of that will be moved into this rig controller here and then next thing is basically get rid of all the references inside the scripts - anything to do with layers also get rid of the animator override controller this this animator here is going to become the rig controller their new one the new animator that we made so don't call getcomponent and start and we're going to assign that in the inspector get rid of this if/else block get rid of all this hand okay layer weight stuff get rid of all this and get rid of the save with impose whoops so yeah just like that and inside the character a mean scripts you can get rid of those aim layer and get rid of this here because we're basically going to all they were doing was changing layer weights so we can do all that stuff inside the animation window now which is pretty cool and so what else doing is you delete this override controller and just make sure to reassign the main the person shooter controller back to the character get rid of this empty animation and I think there is that's it let me just double check what's in the rig controller okay yeah so this has just got the whip and an impersonal thing cool so yeah in summary I um we've now got the main animated controller which is just handling our locomotion we've got the rig layers with the rig controller which is going to keyframe all of the stuff so we need to actually drag this whip and hold a note underneath rig layers and that means that we can actually modify the pivot and the lift in the right hand positions inside this brake controller yeah which is going to be yeah exactly what we need this is one more thing I forgot just on the active weapon script just make sure to assign this animator down here to the rig controller just yeah make sure it is this animator rig controller and not the main one on the character go so just go into play mode now so yeah now you can see that the hand okay stuff because we're no longer turning it off in scripts we need to use the the new rig controller to do that and so if you just select the rig controller and open it up and the animator will just create a new new animation which I'll call like within unarmed maybe like character unarmed or something is a bit a bit of name but whatevs so if you now go back to the scene view and select the rig layers we can now select the weapon unarmed clip from the animation window and if you hit record we can now just key off the hand I case stuff which yeah it makes the character look correct so if I come and play mode and go back in for a second time the hand I K stuff is now it's now working correctly but if I walk over the whip and pick up we need to basically do the opposite now and key the hand I case stuff back on so there's a few ways to do this one way would just be creating like a transition between these nodes here but instead of doing that I'm just going to use like a new trick I found in the old red in the forums so I just wanted to try that out so the idea is basically on the whip and each weapon is going to have a whip and name so we can replace the animation clip with a whip and name string and then inside the active weapon scripts when we equip a weapon we basically get the rig controller and then play a new animation state cool it's like equip underscore and then we'll use the name of the weapon to basically generate the name for the animation state so for a pistol they'll be like a quit underscore and pistol for example so just need to set those whipping names on the prefabs here so for the assault rifle just call that rifle and then for the pistol let's call it pistol and now I just need to go back into the the rig controller here and rename this state from with an N and pistol to light equip underscore pistol so there's there's gonna be no transition here because this will happen automatically inside the active within script so if I just drag the animator window down here and hit play should be able to see yeah okay that's good yeah now the equip state gets into which is pretty cool I think it's quite easy to manage rather than using override controllers but yeah see how we go with that so now the the pistol animation clip basically it needs to be reauthorized all those keyframes earlier and so again just selects the select to the rig controller go to the animation window select the wippen nm pistol clip hit record and now we can start moving their pivot positions and so I'll just zero out the rotation there and I'll just fix this up really quickly cool yeah something like that looks okay and now here comes the fun part so whoo we've got the single single clip single keyframe for the whipping position and now I want to create an animation to holster the weapon so if I just move the keyframes or to light 0.3 seconds or something and basically just create the end pose here this is so cool just using the the rig constraints in the hands of automatically update so I'm just gonna do this like really rough cuz yeah I mean I don't really know how to animate but it'll look good enough for illustration purposes so something like that okay so that's the in pose that I want so there's a few things to fix up with it the first one would be to actually key off the left hand okay so the left hand is loose and then for the right hand I just need to move the hints node back it was the elbows in a funny position but now using this animator window all the stuff is just so easy to do it's amazing I love it and yeah so I mean now we can just see how that looks it looks like just with two keyframes it looks amazing so cool this part is here looks a little bit weird so you just like fix it up just add keyframes like in the middle of your animation where what you think it looks wrong like maybe probably something like that and yeah I mean that's looking like pretty good already so if we come out of play mode come out of preview mode yeah if you notice when you make changes to the animation sometimes I will just default back to the state so you just need to like walk back over the pickup and yeah the play is now played there holster animation it's actually in the wrong direction though so we just want to set that to negative one cool so the next step is actually we just need to create a so we've got this equipped animation and we just want to create a new a new state and I'll call this like holster with an holster pistol so we basically you can use that same animation clip of the animation pistol but play it in the right direction so this one plays in Reverse this one plays forwards and then I'll create a transition in this case using a new parameter so just create a new like boolean parameter called like holster weapon and on the transition just get rid of all the exit time stuff just so the transition happens immediately what I'm gonna do holster weapon set to true and then another transition go in the opposite direction sit to false again get rid of all the exit time and now I just need to sit this boolean parameter and and script so again in the active weapon scripts open up this guy and basically yeah just inside update I'm gonna check if input get key code I mean just pick whatever key code you like but I think pop G uses X so I'll use X and then first we want to check if the if it's hosted already so get the rig controller get bull poster within and then basically yeah just flip it so sit Bull holster weapon not is holstered cool so if I go back into play mode and see if all this stuff works I just sit the umm yeah so you can see what's happening here cool so when we play the pickup and if I push X and it plays in the opposite direction there's something something wrong with this pinholster why is it coming out I spelt it wrong yes it just walked back over this so yeah press X amazing so cool the animation is actually pretty slow so can just fix this up I don't even need to come out of play mode just click the with an animation pistol select all those keyframes and just shrink them down to like yeah yeah that looks a bit better still need to just fix up this right arm at the very end of the animation so just hit record move the cursor to the end and just gonna create like and your keyframe here which will basically sit the right hand I K off but it needs to be on on this up into the very end so yeah it's just create another keyframe at the very end which sits the right hand I K 2 1 and then sits it to 0 on on that Pavia so test that out again yeah I mean that looks pretty cool so now I'm just gonna repeat the same process for the rifle animation so just open up the rig controller and we just need to basically copy these are these states here and rename them to use the string that was set on the pistol pre-fit sorry the assault prefab here so use this the string so rather than underscore pistol should be underscore rifle and then host rifle and then just assign the weapon oops with an nm rifle clip to the states like that and now if we just hit play and walk over the assault pack up go to the animation window and select the within and a rifle clip I deleted all the keyframes just to start fresh so go into the scene view and just press record and then now I can just start positioning everything I'm just going to do this really quickly okay so that's the basic weapon pose and now I just need to create like a holster animation and so basically do the same thing as before just go to where you want the animation to end and then key and the final position for the animation and then we can basically fill in the gaps actually I might create some intermediate keyframes just so I rotate cool so now it's just time to just test all this stuff out if I walk over the assault rifle pickup then it plays the assault animation I can also host holster the assault rifle by pressing X if I walk over the pistol pickup then it place the pistol animation and see I can also holster the pistol by pressing X cool so yeah that's that's it for this tutorial so yea if you'd like to see more videos like this then please like and subscribe and if you enjoyed the video just share it with your friends pretty much appreciated thanks for watching hockey day
Info
Channel: TheKiwiCoder
Views: 44,500
Rating: undefined out of 5
Keywords: Unity, Animation rigging, two bone ik, weapon ik, game dev, ik animation, inverse kinematics, unity weapon, synty, third person character, rig builder, two bone constraint, key framing, animating rig constraints, animation rigging, weapon animations, unity animation rigging, humanoid characters, keyframe humanoid animations unity, keyframe humanoid unity, control rig animations, unity weapon animations, unity inverse kinematics, ik animations
Id: mhKjwNv86cQ
Channel Id: undefined
Length: 16min 34sec (994 seconds)
Published: Sat May 30 2020
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.