Godot 3D - Items and Bone Attachments | Character Animation Tutorial: 7

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
[Music] hello and welcome back today we're going to be going over how to swap from one hand position to another and how to use a weapon or item in a animation tree so what we're going to be doing is we're going to be attaching a sword to the hip and then drawing or sheathing it and then for added bonus we're going to also go ahead and have it so that we can swap between one-handed or two-handed position on that sword and then have a different attack based off of each one of those options and then when you draw or sheath your sword again it will stay in that state so when you draw it again you will be back in your two-handed state or your one-handed State as the case may be so we're going to go ahead and get started here we've already imported in some animations here we've got hand Attack One draw idle sheathing as well as a two-handed attack in idle so we're just going to use a a one-handed draw in sheathing just for efficiency's sake though if you wanted to do this in a final product you probably would want a special animation for drawing or sheathing the weapon when it is in two-handed mode but for now we've got the idle the drawing the sheathing as well as just attacking with your two-handed which is a slightly different attack than if you're one-handed so what we're going to do is we're first gonna go ahead and throw these into the animation tree so if we go ahead and set the animation tree to active and we go up into the upper body State machine here we're going to need a couple new animations so if we add animation for drawing add animation for sheathing add animation or attacking as well as the idle and attacking an idol for two-handed so let's just go ahead and reposition all these so that they don't look so messy so what we're going to do is we're going to set up a couple transitions here first we're going to need a transition from idle to drawing obviously and then from drawing to hand one idle and from there to hand two idle then we're going to need back to hand one idle back to sheathing and back to normal idle now besides this we're also going to need to and from each one of the attacks and then we're going to go ahead and set up all of these various transitions so this one right here is obviously just going to be on enabled it's not going to be Auto and then we're going to set the transition to just 0.1 and right here we're just going to leave this one on auto and we're going to set it at end and we're going to put that to 0.1 then this one is going to be set up the same way but in reverse and then over here we're going to want the transition between the two to be enabled but not automatic but we're also going to want a fairly smooth transition so we're going to set that up just slightly we're going to do the same for right here now due to the way transitioning works if you go from idle to combat sword two-handed what it's going to do is it's going to find the shortest path using a pathfinding algorithm called a star It's actually an incredibly intelligent way to do animation so as a result when we're in idle and we want to draw a sword all we have to do is tell it to transition to here and it will find the path to here and it will do it quite smoothly so let's go ahead and set up the transitions for the attacks as well so we'll set the two transition and then from the return transition we're just going to set it to Auto and we're going to set it at end and put it as 0.2 now down here specifically with the two ended one we're going to need a little bit of a smoother transition due to the fact that we're a ways off from where we're supposed to be at the end of that animation so we're going to set this up to just point and we're going to set that to at end and just enabled so an easy way to get started is to go ahead and go through all these and see how they feel so if we go to idle you can see we put away the sword and if we go back to one-handed we draw the sword if we attack we're fine there and we go back to one-handed if we switch to two-handed and then attack we've got our attack there and then if we go back to idle and then if we go back to there you can see it transitions now I don't like the transition from two-handed to one-handed and then to sheathing so I'm just going to make an interim transition here to make that a little simpler and we're going to set that transition to enabled and set that to 0.2 so now if we go ahead and try that again we draw a sword and go into two-handed and then we go straight back into sheathing and that's a little bit of a smoother transition all right so the way we're going to do this is we're not actually going to touch character base and this is for a very specific reason so the jump animation currently requires calling a method on character base for execute jump velocity now in the animation tree we have that filter down here for that function set to be the lower body and if we put any events on that character base we would have to check that set the upper body able to fire those method calls and because we have the jump on that we don't actually want that so what we're going to do is we're going to break that out into a separate note and we're just going to call this combat controller and this is actually the more efficient way to set up these animations and these sorts of functionality anyways now you can see here we went ahead and brought in a new model it's a very simple sword model that I just threw some simple materials on and so what we're going to do is we're going to set up how these are attached so we do this using bone attachments so if we select the general skeleton here and we hit add new child node we'll just hit bone attachment and we're going to go ahead and create two of these so we're just going to select that and hit Ctrl D to duplicate and we're going to call this one hip attachment I'm going to call this one and attachment and later on if we get shields or anything in here we'll have right hand and left hand but for now this will work just fine now up here in the bow name you can go ahead and select whatever you like in my case it's going to be hips now bone attachments automatically go to exactly where the bone is regardless of anything else you can't move them or anything so what we're going to do is we're going to add a child which is just going to be a node 3D and it's going to be called hip containment and then we're going to do the same thing for hand attachment and we're going to call this one hand container we do need to set a pan attachment so we're just going to find the right hand and now it's in the right place so the best way to set these up and the best way to feel this out is to go ahead and drag what I have the sword mesh in which is an item container which is just exactly underneath the source mesh and we're going to drag this into the hip container and then we're going to see where it is and reposition it as necessary by using the hip container so we can see the sword is not in the correct orientation so we're just going to rotate it like this and that looks about right now if you we actually go to the animation tree you can see if we go to Locomotion and set the movement up now you can see the sword is moving around properly all right so what we're going to do is we're just going to put it onto the hand draw animation on the animation player and then we're going to position it where we actually need to make the handoff from the hip to the hand then all we're going to do is set the hand container to the hip container and we're going to reset the transform on it and then we're going to put that back onto the hand attachment and put the hand the sword onto that container and this will mean this in the exact same location for the actual trade-off however we are going to have to make a slight adjustment just to make it look good in the hand once we're back into combat position so we're just going to go like this and we're going to make a couple adjustments and now when we actually go into the combat position it doesn't look so bad though I do want to go ahead and adjust it a little bit more now obviously animations would look better than this if we were making them custom but for the time being this should work just fine now all we have to do is go ahead and swap off the item container now we don't have to worry about the item container's position it should always just be zero zero zero and then wherever it goes it just automatically is placed into the correct location as long as we zero out its position in rotation so if we put it as a child of the hand container we just zero it out and it'll be in the correct position and that transition should be fairly smooth so we're going to do is we're going to go ahead and set the animation tree back to idle and then we're going to jump into combat controller and actually program out this logic it's not going to be super complicated but I am going to move through it fairly quickly so that we can get on to actually testing but first we're going to need to go ahead and create the two scripts so we're going to call it combat controller thank you all right so we're going to start with a couple of exports we're first going to need the hand container the hip container and the item container now the item container is the node that's going to move back and forth between the hand and the hip container and the hand in the hip container we're not going to touch we're just going to use to parent or unparent the node as necessary then following that we're going to create three more variables and these are going to be strings and it's going to be our upper body State pad playback path as well as our one hand stance name and our two handstand's name these are going to be needed for accessing the playback as well as going ahead and also changing the state of that playback following that we're just going to need a reference to the animation tree and a couple booleans now the booleans are going to be is in combat and using two hands so the isn't combat is going to help us swap back and forth between whether we're in combat or not and specifically use it to reference whether we want to change States when you press F or not and the using two hands is going to make sure that our state stays the same when we're swapping back and forth from combat as necessary now next we're also going to go ahead and override the function for input and we're a little bit behind on C sharp but we'll catch up soon enough so first we're going to check to see if the input is is action just pressed draw weapon and if so we're going to go ahead and get the playback from the animationtree dot get and then upper body State playback path as animation State machine playback we've already done this before so I'm not going to go into too much detail but then we need to go ahead and check a couple of things first we need to see if we are not in combat if we are not in combat and we have tried to draw the weapon then we need to change our state to in combat and we need to go ahead and travel to the proper idle and that will be done so by checking the using two hands Boolean so we're going to check to see if using two hands then we're going to travel to the two Hand stance Plus Idle name and vice versa if we're not using two hands we're going to travel to the one hand stance name Plus Idle and then we're going to also go ahead and create an else statement for the is in combat if statement and all that's going to do is if we are not if we are already in combat we're going to set is in combat to false and we're going to go ahead and travel to the just base idle stance or the idle state following this we're going to need to go ahead and create another if statement and this one's going to say if we are in combat outside of the input.is action press draw weapon then we are going to check a couple different options so if input just is action action just pressed swap hands then we need to go ahead and swap back and forth between two-handed and one-handed and we're just going to copy and paste that playback because it's easy enough to do so and then we're going to check to see if we are using two hands we need to travel to the one hand stance name Plus Idle and if we are not we need to travel to the two handstands plus name Plus Idle this is going to help us swap between the two states and then we're also going to go ahead and invert the using two hands Boolean this is just using two hands equals negative using two hands this is gonna let us do the swap back and forth easily and we're going to make sure to put that after and outside of the if and else if statements or the else statements take note of the indentions specifically on the Godot script variant now we are also going to check to see if input dot is action just pressed use weapon this is going to let us actually attack and once again we're going to copy and paste the playback and this time we're going to check to see if using two hands and if so we're going to travel to the two Hand stance name plus attack one and then vice versa for the use not using two hands now if we later on wanted to set up combos then we're probably going to need to set up something along the lines of an counter that will step up using Attack One attack two attack three so on so forth but for right now this works just fine and we don't need any Boolean or anything after that now we're finally out of the input function we're going to go ahead and create a couple new functions these functions will actually be called by the animations and the first one is going to be equip weapon and the second one is going to be unequipped weapon these will be called when the actual drawing and sheathing animations are being played respectively and in the equip weapon function we're going to go ahead and check to see what the parents of the item container currently is we're going to save that and actually make a mistake here on the godose good variant and copy and paste the playback for no reason then we're going to select that parent and we're going to remove the item container from it this will make it kind of free in the scene it's not really attached to anything then we're going to add the item container to the hand container by adding child now finally we're also going to take the admin container position not Global position but just position we're going to make it Vector 3.0 this is just going to zero it out we're going to do the same for the rotation degrees not Global rotation degrees again you want to make sure this is local variables not Global variables in order to make sure that it is positioned based off of its parent which is now the hand container then we're all we're going to do for the unequipped item unequipped weapon rather is we're going to copy and paste all this and then we're just going to change the hand container to the hip container and that'll do it all right we're back in ghetto so let's go ahead and hop over to the animation tree make sure we are set back to idle and everything is cleaned up and then we'll go back over to the combat controller and we'll go ahead and add the script we just created so let's start with this CS version and then what we'll do is we'll select in the hip container the item container and the Hand container into their respective slots then we're also going to need those animation playback paths not The Locomotion but the upper body and then for the one-handed stance we're going to be needing this one right here but the two understands is going to be the one-handed but with just two and then the animation tree selected that should be everything we need for the script itself but we do need to go ahead and set up the animation so if we hit add track and hit call method we can go ahead and select the combat controller and that'll appear down here at the bottom and if we disable the animation tree we can look at exactly when we need to place the animation event so right there at the beginning and we'll select insert key and select equip weapon then we're going to do the same thing for the sheathing so we're just going to add track call method combat controller and we're going to insert a key for unequipped weapon but we are going to have to step that forward a little bit so right in there so now that should be all we need from there but we do need to set up the filter here so if we go to hips and hide it we should be able to select the combat controller I've already selected it but if you go ahead and select that right there it'll go ahead and be able to call methods now the very last thing but I've already set it up I'll go over it real quick is the inputs all I did was go ahead and create three new inputs for draw weapons swap hands and use weapon with RF and left Mouse respectively I believe f is what's used in Dark Souls for swapping from one-handed to two-handed On Any Given weapon so that's what I'm using here later on if we do end up using Shields we'll have to go over that but for now this should work just fine and if we go ahead and hit Ctrl s and we is activate the animation tree we can go ahead and hit play and see what it looks like all right so if we move around it looks just fine and if we press R we draw a sword and if we press it again we put it back and it's a pretty smooth transition and if we press F we swap between one-handed and two-handed and if we click we attack and if we swap to two-handed we attack with the two-handed attack not as good as if we had custom animations for sure but for the time being at least and for the animations just being pulled from miximo it certainly gets the job done but that's it for now we'll come back to the tutorials next week and hopefully have a Hermit video on actually just this I've Been Working On Combat on hermit so I may actually do a update on that as well over the weekend or maybe just the weekend after thank you all and I hope you all have a wonderful week and we'll see you all back here next week on Wednesday [Music] thank you
Info
Channel: Bonkahe
Views: 5,051
Rating: undefined out of 5
Keywords:
Id: NNPe9zq83iQ
Channel Id: undefined
Length: 18min 4sec (1084 seconds)
Published: Wed Jul 19 2023
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.