2D Roguelike 2 of 14 : Animations

2D Roguelike 2 of 14 : Animations

Welcome back to the scavengers video series. In the previous video we looked at setting up the project and demonstrated the finished product. In this video we’re going to create animations for the player and enemy units from the provided sprite sheet and also setup the player and enemy prefabs. So let’s create a new scene and we’re going to start by creating the player prefab, along with the animations the go with him. So we’re going to choose Game Object – Create Empty and we’re going to label that Player. In our folder Sprites we have a sprite sheet, now this has already been sliced in to multiple sprites. For more information about sprite sheets and sprites you can see the information linked below. In this case we’re going to grab the first set of frames here, which are the player idle animation, and I did that by clicking the first frame and then just shift-clicking the last frame that I wanted. I’m going to take these and then drag them on to the player prefab. And then we’re going to give this a name, we’re going to call this PlayerIdle, so this is the animation that’s going to play when the player is not doing anything. We’re going to put this in our Animations folder. You’ll notice when we did that that two components were added to the game object, a sprite renderer, which is going to display the current sprite frame. And an animator which is going to allow us to play animation. So when we drag those frames on these two components were added, it asked us to save our animation which we saved in our Animations subfolder. It also created what’s called an animator controller, which is going to allow us to manage what animation is currently playing. We’re going to actually move that to our Animator Controllers folder And we’re going to add some more animations to the player. Let’s go back to sprites. And in this case I’m going to select our two PlayerChop animation frames, drag them on to the player, and we’ll call these PlayerChop. We’re going to put this in our Animations folder. Now notice when we do this this hasn’t added another animator controller, instead it’s added that animation to the existing animator controller that’s already on the player. We’re going to repeat the process with the PlayerHit animation. And next we can check to make sure that that’s working. So we can see, there’s our player idling, now the animation is a little fast so what we’re going to do is we’re going to open the referenced animator controller by double clicking on it, highlight the PlayerIdle state we’re just going to set the speed to 0.5, which is going to be half of our normal speed. Notice that our other two animations have been added as states, and later on in the series we’re going to work out how to control changing between those states via script. Let’s check it now. There we go. With the animations done for the player we’re going to go ahead and apply a tag to the player, of Player. Now the Player tag is predefined in all Unity projects, we’ve also added a couple of additional tags, food, exit, enemy and soda. We’ve done that by going to Add Tag and typing those in to these fields. We’re going to set the tag to Player and we’re also going to set the layer. Here we’ve got our default layers, and we’ve added an additional layer called Blocking Layer. This is the layer on which all collisions are going to be checked and so we’re going to go ahead and select that for the player, and we added that the same way, by choosing Add Layer and then typing that in. So we’ll go ahead and select blocking layer. We’re going to do one additional layer related thing for the player, which is we’re going to set the sorting layer for the sprite renderer. Now we’ve predefined some layers here, we’ve got a Floor layer, which is going to be the background. An Item layer which will be rendered in front of the floor, which is going to be the food and the soda. And then a Units layer for the player and the enemies. We’re going to assign the player to the units layer. Next we’re going to add two components to the player, we’re going to add a box collider 2D and a rigidbody 2D. The box collider 2D is going to allow us to check collisions against the player. And the rigidbody 2D is going to allow us to move the player using the physics system. We’re going to set the rigidbody 2D to Is Kinematic since we don’t really want the player to be flying and bouncing around, we’re just going to have him moving in neat grid-based spaces. So we’re going to control that using a script and set this to Is Kinematic. We’re also going to adjust the size of our box collider 2D to make it a little bit smaller so that the player won’t accidentally collider with things in adjacent spaces, only when they’re trying to move in to a space occupied by another collider. There are a few other components that we’re going to add to the player as we go, but for now that’s a good starting point. So we’re going to take that and we’re going to drag it down to our Prefabs folder to save a prefab. Now that we’ve created our prefab we can temporarily delete the player from the hierarchy and we’re going to create our first enemy. We’re going to go ahead and choose Game Object – Create Empty and we’re going to name this Enemy1. Let’s start by adding our animations to Enemy1. I’m going to go back to sprites shift-click the frames of the EnemyIdle animation and drag them on. We’re going to call this Enemy1Idle. This is going to automatically add the components that we need and then we’re going to add the other frames of our animation as well. Add our Attack animation. We can double check that that’s working. There he is, looking good. And now let’s add our box collider and rigidbody as well. We’re also going to set the rigidbody for the enemy to Is Kinematic and we’re going to apply the Enemy tag and assign the enemy to our blocking layer. We’re also going to set the sprite renderer sorting layer to Units. With that done we can drag our enemy down to the create a prefab of the first enemy. And instead of deleting this one we’re actually just going to modify it to create the second one. Rename it to Enemy2. And we’re going to drag in our Enemy2Idle frames. And our Enemy2Attack frames. Now when we drag our animation to our enemy we created a new animator controller. We’re going to move that to our Animator Controllers folder. Next we’re going to open up our Enemy1 animator controller and we’ll see inside that all of our animations have been added here as states. Now what we’re actually going to do is we’re going to delete the Enemy2 states from this, we’re going to shift-click on each of those and then right-click to delete them. Now it’s going to ask if we want to delete the selected assets we’re going to go ahead and choose delete. And what we’re going to do now is because Enemy1 and Enemy2 are going to share the same state machine, they have the same two states of Idle and Attack. What we’re going to do is we’re going to create what’s called an animator override controller, which is going to allow us to use this same state machine and the same script to control it but just play different animations in each of the states. So we’re going to go ahead and choose Create – Animator Override Controller. We’ll call this Enemy2 And so the first thing that we need to specify is what controller are we going to be overriding, so we’re going to choose the Enemy1 controller and drag it in. And we’ll see here, here are the two original animations that we’re going to play, Enemy1Idle and Enemy1Attack, and so we’re going to override those with Enemy2Attack and Enemy2Idle. In Enemy2 we’re going to change the controller of our animator to now use our animator override controller. Now if we play the scene. There we go. Finally let’s drag Enemy2 down to our prefabs folder to create a new prefab. Next we can delete Enemy2 from the hierarchy and we can save our scene. We’ll call it Main and save it in our empty Scenes folder. Now that we’ve got our basic prefabs created for our Player and Enemy unit types we’re going to move on to creating the other tile prefabs we’re going to need to layout the game board. In the next video we’re going to create our floor, wall, food, soda and exit prefabs. Subtitles by the Amara.org community

100 thoughts on “2D Roguelike 2 of 14 : Animations

  1. Awesome tutorial! :3 I just ran into this problem :/ When I drag the sprite textures on the; "Game Object" it doesnt pop up with a window where I can change the name of the animation and directory :c Plz answere fast since I am really pumped up for this xD I have unity 5.1.0f3 😀

  2. I feel very stupid, but when I drag the sprites onto 'player', I don't get this window 'create new animation'. There's nothing in my animation folder either.

  3. I don't really understand why we need to use a Rigidbody2D, especially if it's just to keep it kinematic. Why can't we just use a BoxCollider2D? Or, since all movement will be controlled by directly modifying the Transform, why not even forgo that?

  4. sigh, just one minute into the project and i already come to something thats not working as intended. When i select the 6 playerSprites from the Spritesheet and drag them onto my empty player object, a "Create new Animation" window should open. It doesn't. The Sprite Renderer and Animator objects are created. What can i do to fix this issue?

  5. Is there a way to get the popup box to appear when creating an animation on windows version of Unity? I know you can just rename the animations but then all the animations in the controller still use the old names. Having the dialogue box appear would be far more convenient if its a setting that anyone knows about?

  6. Please help when i drag the sprites of the player idle to the Player folder it automaticly puts the name player to it and i cant rename it ? is there something im doing wrong.

  7. For anyone that wants to see the sprites in a strip like what is shown in the video, look inside the sprites folder window. In the bottom right is a slider. Move the slider to make the list change to icons.

  8. Couldn't decompress package***
    Does anybody have the same problem?I use Unity 5.Can somebody explain me what the damn it is?

  9. Dragging and dropping multiple sprites onto the player creates motion objects, dragging and dropping a single sprite (player hit) instead creates a spirite renderer object.
    You can fix this by creating an empty motion object and dragging the player hit sprite renderer onto the motion. Be sure to name the motion correctly.
    Then create a new state in the animator screen and drag the motion to that.

    (using Unity 5.1f, 64bit personal edition on windows 8 for what it's worth)

  10. what the fuk is wrong with these tutorials i mean i just finished roll a ball with out problems the space shooter tutrail was fuked up the survival shooter tutorial finished after a lot of smashing my head to the wall and after that i was super exited for this one and it's fuked up from the first moment i mean what can i do wrong draging a cupel of sprites into a game object it's just disepointing and run you out of exitement

  11. How do I go about renaming the .anim files without breaking everything? Can't seem to rename them inside the editor, and doing so in the folder breaks the whole thing. The window not popping up to rename is a real hindrance

  12. Wow, my first steps with Unity, and it's an impossible-to-follow tutorial because everything is different 6 months later? Plus, being an old programmer, nothing makes sense here for me.
    I sincerely hope it's possible to use Unity as a classic language+engine, instead of this silly scheme that makes absolutely no sense. Back in the days, I would have written my own external sprite editor, and using them would have been as simple as "open the sprite bank" and "blit sprite #12 at these coordinates". But why make it simple when you can make it complicated..

  13. Hi. Thx for the job, especially for explanations (what is for, etc.) !

    I have a problem at 2:41, after the creation of the 3 player's animations. I can't check anything cause the game window stay totally blue. I finished the tutorial and it's the same with enemies animations. In the next video, i didn't seen neither sprites as you shown, of wall and all other stuff in the main blue game window. Any reason for that ?

  14. So in the new version, I have dragged the animations that were created and called "Scavengers_SpriteSheet_" into "AnimatorControllers" and renamed it "PlayerIdle". Did the same for "PlayerHit" and "PlayerChop".
    It however, doesn't work when i press play? Help. Please.

  15. I dragged and dropped the sprite frames to my Empty in Windows. It didn't ask me where I want it to be saved, instead the controller and the animation were saved in that?

  16. I did the same as the video told . But.
    When i drag modified animator overdrive called "enemy2" the "animation" window of the enemy2 object becomes clear. With no animation scheme as in the enemy1's window…

  17. For everybody wondering how to rename the files without messing up the animator controller, just follow these steps:
    1. Shift+Click the sprites you want
    2. Right click and go to Create->Animation
    3. It will create an animation object and allow you to rename it to whatever you want.

    Otherwise, the animation will be called whatever the sprite sheet is called (Scavengers_SpriteSheet in this case).

  18. When I add the second part of sprites to Player, I don't see another animation added. So I can't change name to "PlayerHit". I also don't see those PlayerIdle in the Animator view. It says Scavengers_SpriteSheet_ for the orange box. And the other box is called Scavengers_SpriteSheet_. This is Unity 5.2.2f1

  19. I followed the tutorial and done what the tutorial showing.
    "Enemy1" with Enemy1 animation and controller, played it correct, drag to Prefabs.
    Rename "Enemy2" override with Enemy1, played it correct, drag to Prefabs.
    But when I drag back "Enemy1" form Prefabs and play it. It shows "Enemy2Idle". So, my result are, "Enemy1" and "Enemy2", sharing same StateMachine AND Animation. The 2 objects just share everything…

  20. Version 5.3.1f1/ Do I need to create the Animations and AnimatorControllers folders in the Assets root? I have those 2 folders under Completed, but do I need to create them on Assets?
    Thanks for the help

  21. Since the way the board is setup contemplates having a variable size, I don't think it is a good idea to hardcore the random range of walls or food that there will be in the board (using the Count class), but it'd be better to declare a percentage of those desired items in relation to the size of the board

    Iriginally if you have a wallcount of [5,9] you will always have that if your board is 8×8 or 128×128. But if you use a wallCounRate of minWallCountRate and maxWallCountRate of 20 and 40 you will always have between the 20 and the 40% of your board filled with walls, no matter the size.

  22. why is this happening

    Assets/Standard Assets/Effects/ImageEffects/TiltShift.js(58,152): BCE0019: 'farClipPlane' is not a member of 'UnityEngine.ComponentAssets/Standard Assets/Effects/ImageEffects/TiltShift.js(58,152): BCE0019: 'farClipPlane' is not a member of 'UnityEngine.Component

  23. Wow, i learnt a lot from this session. For those who can't download asset from asset store due to version difference, google "unity 2d roguelike github" and get from there.

  24. I'm following the tutorial to the best of my ability, but I CANNOT get the sprites to show up on my screen. I've noticed at 3:08 that there is this Entry file that I don't have. What is going on?

  25. Note: Your Project tab needs to be set to "Two Column Layout" in order to see the sprite rollout at 00:50. If the folder is set to One Column Layout, the sprites will need to be selected individually by name (rather than by sprite).

  26. I recomend making a new folder where you put all your stuff, so it wont mix up with the stuff that's already there.

  27. Don't understand. Followed video and nothing when testing just a blank blue screen. Camera started out at -10 Z but changed that and still nothing. Have animator setup that it starts on the idle animation for the player. Not a useful tutorial. Obviously the author isn't explaining all of his settings which would be a real simple and easy thing for him to do. Thumbs down.

  28. FFS! Most of these tutorials have issues, either with versioning (i.e. videos done for Unity 4 not 5), or as in this one, a patch invalidating something. In all instances the video comments that have been sloppily slapped ontop of these old videos DONT PROPERLY EXPLAIN WHAT TO DO! For a novice, this makes the video borderline useless. You guys have had a long time here – please update these friggen videos properly OR take them down so you dont confuse people OR release more videos relevant to current unity!

  29. I have a problem at 6:00 because my enemy doesn't show up but i have the same settings as the player and the player shows up. I have tried to change the z of the main camera but -10 is the only one that works with player(which is at z 0) can anybody help me please?

  30. Just in case anybody makes the same mistake as me, if you can't see the player when testing it, make sure the player's z position is set to zero

  31. I cannot view Animator Override Controllers in my Animator window. Any reason for this bug? I have the newest version. please help!

  32. If you don't see your player when you click play drag the first one of the 6 idle animation sprites into the 'sprite' field under your player. Then make sure your player is at position 0, 0, 0, and that camera position is 0, 0, -10.

  33. I could watch 1000+ other videos on a unity concept on youtube and be totally confused. Watch this guy once and figure out the whole thing. Am I the only one? Must be the way he explains it or his voice. Also might have something to do with him working at unity. Who knows. I hope they pay him well

  34. Holy CRAP. I know this is an "intermediate tutorial" but you are cruising along super fast with everything. I'm pretty comfortable with unity but I still had to pause every ten seconds to catch up to speed talker here. This is better suited as a "Speed run tutorial."

  35. Can't see the player on the game scene, adjusted main camera to match the positioning of the player sprite. I can see the player on the scene screen though.

  36. Hi,
    Just to note that sometimes animation aren't looping

    So be sure to tick the Loop Time checkbox on each animations.

    Great tutorial.

  37. im from 2017! I isprianced a probrem! the compleated game dosent work! and nor the animacion work! can you help me?

  38. The video references some additional information on sprite sheets, but I cannot seem to locate it on the Unity Learn site. Any ideas?

  39. I'm on Windows using 5.6, and dragging the sprites onto the Player GameObject doesn't work. I solved my problem by selecting all of the sprites I needed, creating animation, and then dragging that onto Player

  40. "For more informations about spritesheets and sprites you can see the informations linked below"

    I want more informations about sprite sheet creation, I want to create my own animations, but where are those informations? Can anyone proveide me a proper link or something?
    Very nice and useful video though! 🙂

  41. When I added the animations to the game object Player and then tested, I found that it kept running the "PlayerChop" animation instead of the "PlayerIdle" animation. How do I change this?!?!?

  42. Broken
    the notations are lacking in clear information and are NOT covered in the upgrades pdf that accompanies the asset bundle.

  43. When you create your animation by dropping the sprites on the player, if the animator doesn't group up the existing animations, just make sure you are creating them in the same place as the existing animator >controller< (named "Player" I guess), then move your .anim in the right folder.

    Have fun !

  44. This tutorial is much to fast and confusing as it seems that some steps like creating the correct folders have left out or worse where subject to a change after an update.
    Take your time in this beginner tutorial and let the trainee do what you are explaining and don't jump to the next step right after explaining the step before.
    Sorry I canceled it after 2/14.

  45. well… I needed to manually add some folders to my files, the ones that you' ve had predefined. that' s weird, I' ve manager to go through this but…

  46. "For more information about sprite sheets and sprites you can see the information linked below" – There's no information linked below -_-

  47. I've made a sprite and wanted to resize it because it's way too small, but how can I mantain the same pixels when scaling? Because some of them gets lost while resizing it…

  48. where do I save my animation files? the only animation file in my project folder is hidden deeply in the assets which already has all the animation loaded inside…..

  49. OK, I see you used the animator override controller for enemy 2, but how do you then use the same code across both enemy 1 and 2 to make them perform the various animations? Because, if you have to call the various animations by name in code, and I don't really understand any other way to do it, then how does making the animation override controller save any time or whatever, if everything is still called and run separately by its own name in code and stuff?

  50. A lot of the complaints with this video are valid, but the video is still pretty good.
    – It's out of date
    – He doesn't actually go through creating some folders, which causes confusion on where to save. Just pause, think about it, watch where he's saving them, and make those folders yourself.
    – The first annotation is pretty terrible at explaining what needs to be done. The few others after that do well at explaining.
    – He speaks quickly. Just be prepared to pause a lot (ctrl+tab is your friend!)

    Take your time! It's still a good tutorial, and part of being a developer is reading between the lines when it comes to things like version discrepancies. If you want to be a developer, then get used to that now.

  51. NOTE: I'm learning 2018.2.13f Personal, downloaded in October 2018. What I have to say may not be relevant to future versions.

    Okay, so I learned a few things that might be worth repeating for other people.

    One: At 1:18 when you discover that there should not be an animations folder, don't try to take your existing PlayerIdle and just copy it over to Sprites. It won't work when you test. Instead, create a new PlayerIdle, overwriting the existing one, and you'll be fine.

    Two: Just in general, whenever one of the tutorial's out of date shenanigans leads you astray, compare it with the stuff in the _Complete-Game folder (or whatever they're calling it in whatever version you see now.)

    Three: I found the Tag and Layer stuff they were talking about in the first video. Apparently that stuff is now on each object (or always was and that just wasn't clear). You can find it right under the top "player" thingy in the Inspector after you create the Player object.

    Four: Once you start getting the hang of it, this is actually kinda cool. 😉

  52. Frustrating to try and figure out how to follow along with an out of date video. Would recommend users skip over this.

  53. For those wondering where the "is kinematic" checkbox went, it's moved to a dropdown menu titled "Body Type" that defaults to "Dynamic"

  54. If you set the default animation state to PlayerHit and don't check "is kinematic" on the player's rigid body component, and hit play, you'll get a lovely scene ;D

  55. Ok, I was struggling at first like a lot of you. What I did was created a completely new Unity project, and copied over the sprite sheet from the tutorial project into my new project's Assets folder (here I also created Sprites, Prefabs, Animations, etc folders to mimic the structure used in the tutorial). Surprisingly, once I approached it that way, things mostly seemed to work exactly as the tutorial outlines. I think if you try this by opening the tutorial project, there's a lot of boiler plate and settings changes that are causing confusion. This is as of 6/18/2019

  56. NOTE: I'm on version 2018.4.8f1, and when I added the box collider 2D and the rigidbody 2D to the player prefab, I had some errors showing on the box collider. I had to manually set the size to x = .9 and y = .9, as well as untick the box labeled "Used By Composite". Hope this helps others!

  57. I don't like the idea that enemy2 override from enemy1, instead, I think it should enemy1 and enemy2 override on base common animation.

Leave a Reply

Your email address will not be published. Required fields are marked *