Unity RPG Tutorial #14 - Sword Animations

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hey everybody this against Plus James and welcome back to a uz or PG tutorial series the last semester we added a sword for our player to walk around with and be able to kill our enemies but we need to make it look a little bit better so it looks like it's actually moving around with our player in the world so last time I we made the sword be a child of the player because we wanted to M be able to move the sword independent of the player basically but we also want to make sure that we can switch our sword out for other objects in the future so what we want to do is actually make another child object and to put the sword within so that if we switch the sword for say an axe or any other object and we'll do all the movement on the container that disorders within that will cause a weapon and and whatever movements and rotations will happen on that and then the sword will just react because it's a child of the weapon container the sword will react and move and then if we switch a sword for an axe or anything else that object will be within the weapon holder and that will move the exact same way that we want to do so to do that and we could kind of actually easiest way to do is just get our player okay click on create a and we'll call this empty we'll call this a weapon like I just said weapon like that and then we'll just drag our sword into the weapon child I'm gonna make sure that the web the sword is centered exactly within the weapon so we'll go to the exposition here and put that to zero and the y to be zero also you see you move around like that and we want to grab the weapon using our move tool and move us to roughly the right place that we want them and as you can see it's kind of our sword has moved behind their player now it wasn't front of him a second ago but we haven't actually really made any changes and the reason that's happening is because I player sorting there is one and our swords sorting there is one so normally what we would do is if we set our certain area to be to for example the sword will appear in front of it and that'll be fine we can move the sword into the drapes we're actually gonna put it out of position now because that'll help us with some animations in a minute and but and so we normally put an order in there to be higher so it appears in front of player are lower if we wanted to be behind the player but we're gonna leave it at one because when we're doing animations we're not able to change the order in the layer so if we just click on the player for a second and go to our animation window which should be active here we go okay so the players move when the players move them down that's fine we'd want a sword to be in front but when our player is moving up like this we'd want the sword to be in this hand and we want it to be behind the player but when we're doing animations we're not able to change the order in layer here and it's kind of a strange omission I don't really know why it won't work books there's a very simple workaround first because we keep our order in layer the same the only way the that unity then knows how to position something above or below the player is by the Z position here so if we were to increase the Z position I have the player of the weapon here so if we move that up above zero then it'll move behind the player and if we put it below zero it'll move in front of the player it's kind of the opposite to have the the sorting layers works basically it was just a little bit confusing but if once you get the hang of it it's not too bad so I'm just gonna put this back to zero for a second so what we want to do is move the swords at using the Z value in front or behind the player just depending on which direction is facing so now let's actually go and put those animations into place so we'll start with our player moving down so we have our the only minute animations that we've got going on at the moment it's just switching between the sprites so what we're going to do is animate it so that the weapon moves to the right place on each frame of the animation so on the first frame here we know that our weapon wants to be damn well have it over his hand kind of like that so we want it there and we actually you although it would look ok to have his sword position like that we want to have him walking with a sword kind of pointed in front of them so what we'll do is on the rotation here go to the Z value and we can click and drag it upwards or we can just because we want we know we want to point straight down you set that to 180 oh and doing that has revealed a little bit of a strange thing so our weapon oh that was my bad because I move the sword apparently at some point okay let's just counsel these bits of animations I'm just gonna highlight these two that we just created and then right-click and delete those keys so now our sword is gonna left here upside down turn off the animation okay so apparently what I did a second ago I moved the sword within the weapon and that's what we don't want to do it all we want to make sure we're doing any kind of movement on the weapon itself so I'm just gonna set this to zero back into the center where it should be like that no it's okay okay so we just need to remember to move the weapon and not the sword if we if we move the sword at all it's gonna create havoc and problems that we don't need so we'll go back to square one again we're on our player move down and animation and make sure we're on the first frame and on the first frame we're gonna move our weapon to the right position and we're gonna set the rotation I spin around like that and you can see it's actually spinning properly this time so we set it to 180 so it's pointing down I'm just gonna make sure we're covering over this little gap here we don't wanna have to worry about being too accurate it's okay for this time beam okay so we've got our weapon pointing down I - if we move to the second frame we can see the hand doesn't move so we're okay to keep our sword there like that moves his third frame again the hand doesn't move so the sword is fine like that and then our fourth frame the hand moves up to there so what we want to do then is just can drag this up to there like that I just move that a tiny bit over just to cover that little white cap okay so then we've got and the first frame where the sword is here and the fourth frame where the sword is here and that's the only movement we want happening because we've got sprite-based animations we wanted to just go from first place to the second place but because of the way animation is working usually what unity does is it goes okay we've got our first frame here and then we've got our last frame here will automatically try and fill in all the gaps so if we go to our second frame we can see the sword has moved up a tiny bit and then retired frame we can see the sword moved up a tiny bit more so if we just hit play here we can see what we actually get is the sword kind of slowly drifted into place and that just looks completely wrong that's not what we want at all so we stop that plane and the way we can fix this is if we highlight by clicking and dragging and now mouse clicking on one and dragonbug clicking to the side one and dragging across and if we right-click and hover over both tangents and click on constant so what that will do is it'll say it'll only basically move straight to a position when it's told to move by one of these little diamond key frames so if we hit play we'll see the sword just goes beep right into position same way works in the sprite animation that's perfect that's exactly what we want and we want to do as well it's do the same thing for our rotation both tangents and concept because when we switch from one rotation to another we want our sword to click exactly into position if we don't do that what'll happen is when our players say goes from walking up to walking left we see the sword kind of swing slowly from point upwards to ought to point in towards the left but what we want is it to instantly snap into the right position okay so that's perfectly fine and so we need to do basically the same thing now with our other animations but what actually we won't see it with this animation we will see in the next animation so I'll come back to what I was about to say now in a second but so we switch to our player and move left and now we have our swords kind of pointing up like this in the wrong direction and so we're going to click and we're gonna drag our weapon again drag it over to here we're gonna set the rotation to 90 like that and actually move it we'll put the sword round about there and the problem at the moment is if we're looking at the sword we can see the sword is appearing in front of the player but we and when the players face in this way the sword is in the right in his right hand so you want to sort be behind so again as we discussed oh my God we're gonna set the Z value of the position to be 1 so that the sword pops in behind the player and we just go to our frames here we can see in the first frame our hand goes forward so we'll move the sword forward to there like that third frame the hand moves back so we'll move it back to there for frame the hand moves back even further so we'll move the back again ok so we got our sword go on impeding our positions but again if we hit play now the sword is kind of sliding it actually looks kind of like a nice little smoother animation but that's not what we want we have a sprite based animation so we need to pop in between places so again and we're gonna click and drag but this time we're gonna select all the position keys and I'm the rotation one that we had so we can just do all them at once and say both tangents constant and so now if we go back again to the first animation back here so we've got our sword here I'm just by default at the moment it's appearing in front of the player but there's nothing really explicitly saying that it should be in front of the player because it's gosh we've got our 0 and our z axis here which is the exact same as the player so unity cuz because it hasn't been told exactly what to do it could just decide to put the sword behind the player and so we want to make sure is that unity knows exactly where the source should be which is on our weapon position here here we want to make sure Z is that - more so it's guaranteed to be in front of the player and on our other keyframe here because we and says and -1 originally we need to set us again here whereas on the second animation because we set it at the very first frame then on the second third and fourth frames it stares at one okay so we move to doing our moving right animation so this again should be relatively straightforward we'll move our sword into the rough position turn it around so we'll set this to be minus nineteen like that and it looks like it's roughly in the right position there so we need to make sure again that the Z value is right so we say that the minus one so when I will go to our frames and see where the sword moves we need to move it back then forward against there and then finally forward and a little bit up to there so we see we got our sword moving nicely then again we'll highlight the bottom two rows go to both tangents constant and then we get our player moving up and we'll do the exact same thing get our weapon move it over to here like so and again we need to set our Z value to be minus one we all said it's the one this time so that goes behind the player and although the sword is pointing in the direction we want at the point we need to make sure that it will go to this position when we switch animations so we need to actually set the rotation specifically so what we can do is if we were to type in just zero there like that it's already zero so it's not changing the thing so it won't record that in the animation here so we need to do is change the Z value to just some random number and then set it back to be zero again so then it knows that it should be zero here okay so whenever we move the sword so in the first frame the hand goes up a little bit so we'll move it up a little bit like that third frame it goes back down to there and then for frame it stays in the same position so that's fine so again we'll highlight over them right click and say okay so that's perfect so now and we need to set music the same thing for our player facing different directions so it's basically just doing the exact same thing again but for now we want to just test and make sure that our animations are working properly so we'll go into our game here and as you can see we can now walk around a little bit we can see the sword is moving around just the way we want them to whenever we stop moving we can see the sword is kind of just floating there not the way we want to do it all because we haven't set any animation for that just yet but we can see as he's walking along he's actually am carrying the sword just the way we want so if we walk into this guy here nope didn't catch him but this guy oh no we missed him with the sword but that's okay because we're not actually attacking anything if something happens to run into our sword it will kill them but we're not actually trying to attack them at the moment okay so what we can do now is yeah we need to set adds rather quickly we need to set the sword for when it's facing different directions so when he's facing down here we again all I want to do is move our sword roughly into position so there's the value to 180 like this make sure that it's and above the player which is minus one and we'll just move it over like this and again we want to make sure that the sword definitely clicks into the right position rather than slowly sliding so we'll make sure and say both tangents constant no we don't want to create new animation it's a clear face and left so this time we move this oh we can actually see the sword is kind of annoying and so we'll do the rotation first set it to - move the sword kind of roughly into position here and we want to make sure it stays behind the player even though it is already there right now so make sure and set that to one and again let's make them both tangents constant so for facing right then we have oh no we don't want to move the player we want to move the weapon will the weapon should be in front of the player this time so we'll say -1 Z rotation should be minus 90 and put a sword in our hand no your hand like this that's where we put it last time there we go perfect and again we'll do the exact same thing we make sure both tangents are constant and then finally we have their player face them up and when the players facing up we want our weapon over here in this hand and we want to make sure it is no not minus 1 it is 1 so it's behind and again we want to make sure that the rotation goes to the right position it RS and just stay wherever it was when where ever wants it to be basically and so make sure again put our Z value just give it a random value and then hit 0 so it stays just exactly the way we want it ok so now we should have with all them done should have when our player is walking around he'll stop and hold the sword in the right position each time so I freeze walks perfect he's got the sword just the way we want them to perfect so now we can see we've got our sword walk our dude walking around with his sword in our world you know in a fun and interesting way basically and so yeah so that's the basics of and a little bit more animation to the player so we're we hadn't covered actually moving things in our animator yet but now we can see it's relatively straightforward and you can use the same tools to create whole animations for your game if you wanted your player to like walk to specific areas and stuff like that or you wanted to set up cutscenes and things you could just use the animator to do all of that for you it's quite handy in that way and but for now we've we've covered enough of a player moving around we will of course return to actually attacking things having an animation for attacking and such like that but for now we've got our player moving around and he's got a little bit of for when ad these guys kind of come at him let's see if we can get one there we go we gotta we got it we got an enemy we can take care of these guys so thanks for watching this episode and I will return soon with some more RPG goodness thanks for checking out this episode and if you want even more games + jams goodness make sure you hit those subscribe and like buttons you can also find me on Twitter and Facebook by following links on screen where you can find out all the latest news about the channel but if you want to help support the show check out the patreon page where you can get exclusive content in return for helping make the channel even better thanks for watching and stay tuned for more
Info
Channel: gamesplusjames
Views: 50,281
Rating: undefined out of 5
Keywords: gaming, let's play, play, games, entertainment, retro, fun, Role-playing Game (Game Genre), unity rpg, unity 5 rpg, unity rpg tutorial, rpg game tutorial, unity rpg game tutorial, make an rpg tutorial, unity rpg player
Id: yACBhaBzaIA
Channel Id: undefined
Length: 18min 21sec (1101 seconds)
Published: Fri Jan 08 2016
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.