How to Setup Unity3D Sprite Animation - With multiple sprites

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
it what's up Jason here from unity3d college in this video I'm gonna go over some sprite animation basics and show you how to set up a sprite that animates and then I'll show you how to set up a multi-part sprite that's animating so what I've got here is just a head of a character and a body for a character I'm gonna start with just the body we'll animate that show the basic steps and then we'll combine in and do a head and body as two separate parts that are animated so the first thing you have to do is go over and just change the texture type to sprite if it's not already on sprite you need to switch it and hit apply and then since this is a multi sprite sheet I need to change the sprite mode to multiple instead of single and then I'm just gonna go into the sprite editor again it's gonna just ask me to apply so just hit apply and then up here is the option to slice the sprite if you just choose this and hit slice with automatic set it will most likely just automatically slice your sprite I haven't run into a case yet where it wasn't able to slice them correctly but there is a manual version that you can do grid cell count and grid cell size if you really need to customize it and you can kind of see in here if you're not familiar with this there's little white lines right around the edge it may be kind of hard to visualize I wish they were slightly different color because they don't show up really great on the transparent background but it's sliced now and if I hit apply and close out the sprite editor you see the body is now expandable and we have a bunch of different sprites here and go through all the different sprites now what I want to do is create a new sprite in the game so I'm just gonna go to game object 2d object and then sprite I could also just drag out the body if I wanted so I'll just tell this body and then I want to add some animation to this thing so oh look you can see it's already got the sprite on it what I want to do now is create an animation so if I want to animate through all of these sprites I'll go to the animation tab right here or just under window and animation with the body selected and I'm gonna hit create I'm just gonna name this body it's just going to be the animation for the body parts now I'm going to pull the animation tab off a little bit so that it's undocked from the project view because I need to pull things from the project view so I want to get all of these sprites into this animation so that it'll animate across them I could drag them out like this you know one at a time go piece 1 part 2 part 3 and you can see I can kind of play and start seeing the animation there but an easier way to do it is just select them all drop them right in right at the beginning and you can see every sprite got put in there I can also expand this out with this little bar here it's a newer feature if you're using an older version of unity you may not have this yet I think it came in in 2017 maybe 5.6 and you just drag this and you can slide it out and make it longer if you want you can add an extra transitions or extra frames customize it a little bit I don't need that for this though so I'm just gonna slide it back down I'll just hit play and you can watch and see the legs running all right so that's kind of cool but like I said I also wanted to show how to do multiple sprite animations so we can have the head and the body as separate parts then we can do other kinds of cool things with them with if they're separated right so let me first first go to the head and change it to sprite and I'm gonna switch this over to multiple and if I just go and hit sprite editor right here it's gonna automatically again ask me to apply so I can kind of skip that step of hitting apply go to slice hit slice again to auto slice them and we'll apply that change and let's go back down here and look we've got the head with all of the pieces and here you can see it just kind of Bob's up and down right so it's a nice little bobbing head animation I'm gonna drop it out here show you what it looks like and then we'll combine it into a single animation so here's the head and it's worth noting that the head right now is behind the body I want to move that forward to do that I'll just make the order in layer 1 so whatever the order is they're drawn the higher numbers are on the front lower numbers on the back the default was zero so bodies at zero heads at 1 so the head will render on top of the body now if I create an animation for the head I can make it Bob up and down like I said but what I really want to do is just combine them make a single animation that does the head and the legs so to do that first thing I'm going to do is just delete this body animation I don't want it anymore delete that animator controller and I'm gonna create an empty game object and this is gonna be my robot I'll take the head and the body and make them children of the robot actually I'm going to name this robot sprite because this is actually just the visualization part so if I were building out an actual game object this robot sprite would be a child of another robot object that does more stuff it has all of the logic and then we have the the visuals down as one layer lower as a child so with the robot sprite selected go into the animation window again and now there's no animation for it so I'm just gonna hit create a name it robot full sprite it's a body in the head and now I'm gonna add a property so if I hit add property I'll go to the body first expand out a sprite renderer scroll to the bottom and then here this stupid little scroll bar has to go to the right for you to see the plus if you don't scroll over you may not know that you can click on it and actually add it so you got a scroll over and hit the plus and now we've got an animation that has the body sprite in there so let's fill that in so expand out the body again select all of the pieces and just drop them right here all right we're halfway done if I play you see now it's playing that part let's delete out this extra keyframe at the end we don't need that that's what was causing that long delay there so I hit play again you can see there go the legs and the arms he's kind of wobbling around but the heads not animating yet to do that I'm just gonna add another property go to add property expand off the head expand out the sprite renderer go down to the sprite and again scroll to the right so you can see the plus hit plus and then let's find with the sprites for the head so I'll expand out the head down here in the project view select head 0 through 13 drop them right on here expand that out oh no that was good we just have an extra frame here I think this head animation is maybe one frame longer let's just delete that I'm sorry one frame shorter let's hit play now and see what it looks like there we go so now we've animated two sprites with one animation on a single character and now before we go I want to show you one more cool thing of splitting up these sprites one of the benefits that we can take advantage of so if I hit record here and then I'm gonna drag over the white line to about halfway through then I'm just gonna move the y-value of the head so I have the head selected and I'm just gonna raise this up a little just click drag to the right raise it up and then let's hit play and see what happens you can see now the head is popping up and down in fact let me copy this frame right here and paste it at the end and then let's play again and you see now the head just kind of Bob's up and down - it's not the best animation for this guy but you can imagine we could do some really cool different effects one of the things I was looking at doing with this guy you know having these things split out is just rotating the head maybe doing an animation where he rotates and looks his head upward and looks down to see different things it's a lot of extra little functionality you can get where you don't have to go in and keep building different sprites you just modify and move some of the parts around so I'd say try it out play with the sprite animation for sure it's pretty easy to set up there are a lot of free sprite sheets you can find online just google sprite sheet and find just about any character that you're interested in some version of it is out there probably try it let me know how it works if you have any questions feel free to drop a comment or hit me up on the site at unity3d college and don't forget to just like and hit subscribe thanks
Info
Channel: Jason Weimann
Views: 112,644
Rating: undefined out of 5
Keywords: Unity3D, Unity Sprites, Unity3D Sprite, Sprite Animation, Unity3D Sprite Animation, Unity Sprite Animation, Animate Sprites, Animated Unity Sprites, Animate Unity Sprites
Id: RGYdzTOvKXQ
Channel Id: undefined
Length: 8min 4sec (484 seconds)
Published: Wed Aug 30 2017
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.