Animation Workflows

Animation Workflows Hi, I'm Joshua Kinney, and in this module, we're going to understand the basics of animation in Unity. In this first clip, we're going to take a look at the animation workflow for Unity. So there a number of different ways that you can create animations for Unity game development. One way is to create the animations directly inside of Unity using the animation workflow. You can create animation clips as assets, and then you can begin to add keyframes to those assets through the Transform component. So to give you an example, if we were to select out treasure chest here, you'll notice that it has a transform component. We could begin controlling the individual parts of this chest through it's position, rotation, and even scale, and we can animate these through keyframes. Now, before we get into that process, let's take a look at another way that animations are created. Here we are in Maya, and you can see that this is our main game character. The character was modeled in 3ds Max, in Maya, and then it was textured, and then it was brought into Maya to be rigged, which means to add bones, and then skin the mesh to the bones to where the bones would drive the motion of each vertex in the mesh, and then controllers were added to make it easy for animators to create the animations themselves. So here you can see our main character is in what's called a walk cycle. Now, this animation can be looped over and over again to create the illusion of endless walking. This type of clip is necessary for game development because sometimes whenever the player is moving around, we would always want the character to walk and run endlessly until the player has released the mouse button or whatever the controller might be. Now, this animation can be exported out from Maya and into Unity as an animation clip. Let's go into Unity and talk about how to create those animation clips. So back in Unity, you can see in the game we have our player character already set up. You can see that he is in what's called a A pose, or sometimes also known as a T pose, but this is the default state where the character has been rigged, ready to animate. This is just storing the model in its present state as well as the rig in its present state. Now, whenever we hit play, you can see that the character goes into an idle animation, and typically, this is just an animation showing that the character is alive and ready to be controlled by the player. We can left-click and we can click anywhere on the environment, and you'll see that the player object is rotating, and moving, and animating. Now, we talk more about how to set this up later. Let's start small with the animation clips. So we're going to go over to our chest object, and we're going to add what's called an animation clip. An animation clip is simply going to hold keyframes that holds data from the transform object or any other component that might be on the object itself. So to create an animation clip, we're simply going to go to our animations folder. Then, we'll right-click, Create, Animation Clip. Give this a name, and we're going to call this chest_open. Now, once the clip has been created, it is now an asset. However, it doesn't have any keyframes or information to tell it how an object should animate. Let's go ahead and open the animation window by going to Window, Animation. I'm going to left-click and drag the tab at the bottom of our Scene View and dock it right here. Now, you'll notice that I don't really have any control. I don't know what properties I'm trying to animate at this point, and so I would need to associate the chest to this animation clip. This can be done easily by selecting the chest, and then, with the Animation window open, you'll see that it's asking me to create a clip. Now, we've already created one, so I could just simply use this object and tie it to the chest_open by hitting Create. Now, it's asking me to create a brand new object, but I'm just going to use the existing animation clip that we created. This will now associate it to this object. Now, you can see that we are working with the chest_open animation, and we can now add properties on what we would like to create. Now, before we get into creating keyframes, there are a couple of things that are really important about the animation window. The animation window has playback controls. We can play the timeline, and you'll see the scrubber moving across at a specific rate. That rate is determined by the amount of samples that you've set, so as you can see here, we have 60 frames, and that equals one second. You can notice that this says 60 frames. We can modify this to use 24 frames per second and hit Enter. Now, 24 frames per second is typically used in film. You just need to make sure that you're being consistent with your animations, so if you use 24, most of the time I see people using 30 frames per second, but typically 24 or 30 is pretty good. I like to stick with 30. Now, once that has been created and we know how many samples or frames we're working with in a single second, we can now begin to add keyframes. To create a keyframe, it's very simple. Select the object that you would like to have a keyframe created on. I'm going to actually select the chest top for this object, and then I'm going to click on Add Keyframe. Now, you'll notice that this didn't actually add a keyframe to our timeline. The reason for that is because it doesn't know what property to actually assign this to, so let's click on Add Property, and now we get the option to choose what we're adding this to. So we can add it to the chest top, and then we can access the transform information here. Let's go ahead and expand that, and what we want to do is we want to have this chest open by rotating, so we're going to add the rotation data. And now, you'll see that we have a single keyframe at the beginning and at the end. Now, what we can do is we can go to the very last frame, and let's say that we want it to take a single second for the chest to open to its fullest extent. So we would move the time slider to the last keyframe. This is indicating that we are working on the last keyframe. Then, we'll hit the Record button. Once you hit the Record button, you'll notice the timeline turns red, letting you know that anything you change from here on out is going to affect the keyframes. Now, we are working on the rotation data, and so we can just come in and simply rotate around the x-axis by adjusting it here to where we want. We could also interactively rotate it by going to the Rotation tool and then rotating it to the desired position. In this case, I will have it come back and rest at this point. So once that has been animated, we can now turn off record and preview that animation. So now if you hit Play, you'll see that it's opening, and we now have created our first animation clip. Now typically, we want things to be a little more interesting than this, and so we would add more keyframes to create things like secondary action and different principles of animation. So if you are unclear about animation and you want to get more into that, there are some great courses on Pluralsight that would allow you to see things like different principles of animation. These are typically what makes animations come to life and are more appealing. So now that we've created our very first animation clip, let's take a look at how we can get it to apply to the chest itself. If I were to come in and hit Play, what you would notice is that the chest has not even animated open. Now, you'll notice that it is opening and continuing to open. What is causing it to do that? Well, the next clip, we're going to take a look at the animator. The animator is what controls the animations on a specific object, and we'll learn more about it next.

Creating Animation Clips

Creating Animation Clips In this clip, we going to learn how to create animation clips, and we're going to learn about the animation window. So to begin, let's go and open the animation window. To do this, we'll go to Window, Animation. Let's go ahead and left-click and drag the tab and dock it at the bottom of the scene view. Now, you'll notice that the animation window is grayed out, and the reason for that is because we don't have an animatable object selected. Let's go ahead and select our chest. You can select it in the scene view or you could select it from the hierarchy. Now, whenever you're creating animation clips, it might be helpful to know that the typical workflow is to select the top-most parent, and then add the animation clip to it. Doing so will give you access to all of the objects that are in the game object itself, so you'll notice that the chest game object is just an empty game object, and then it has the individual pieces grouped in it as children. So you might be tempted to select just the top, and then create an animation clip for that, but it's not necessary. We can select the top-most game object and then choose Create. Let's go ahead and hit Create now. This will give you the option to save your animation clip in a specified location. In our case, we're going to use the animations folder that is already provided. Let's go ahead and call this chest_open. Hit Enter, and you'll notice that it creates a few objects for us. The first object that it creates is the animation clip itself. It also creates an animator controller called chest. Now, this animator controller is applied to the animator, which is also created, and it applies the animator controller chest to the controller parameter, so it does a lot of work for you automatically. Now that we have this selected, we can now begin to add keyframes to our animation clip. Before we begin doing that, let's take a look at the interface. In the animation window, you have the playback controls. The playback controls are pretty standard. You can begin to record animation by clicking on Record, and then any movement or modification that you do to the object, it will begin to record those keyframes on the timeline. You also have the ability to step back by going to the beginning of the animation clip, or you can go to the end of the animation clip. You also have the ability to step through the keyframes by going through a previous keyframe or going to the next keyframe, and then obviously you have the ability to play the animation clip. Now, you'll notice that the time slider is moving horizontally through time. The time slider currently is at frame 39, so this allows you to type in which keyframe you would like to be on. In this case, we could say, let's go to frame 20, type in 20, and hit Enter, and you'll notice the time slider updates accordingly. Now, any time that you move that time slider, it will update here as well, and it gives you a pretty good indication of what frame you're currently on. Now from here, we have the list of animation clips that are available for this game object. In our case, we only have one animation clip, but it's important to know that you can create multiple animation clips per object. To do this, you can click on the list and choose Create New Clip. Let's go ahead and call this chest_close. Hit Enter, and now you'll notice that we have two clips in our project folder. Now, we have the ability to click on the list and choose which animation we currently want to work on. In our case, let's choose chest_open. Now, from here you'll notice we have Samples. Samples is going to determine the frame rate of your animation or frames per second. By default, it sets it to 60. 60 is perfectly fine, but you typically want to come up with some sort of workflow that is going to work for you and your game development team, so if you're creating a game that is a fast-paced, first-person shooter, you probably would like to target 60 frames per second in your game, so it might make your animations look a little bit better if you set things to 60 frames per second. Now, even if you animate at a lower frame rate, it's not going to affect your game, so you're not really doing anything wrong by setting it to 30, or 60 for that matter, but typically in most game development pipelines, we'll use the frame rate of something like 30. Now, you'll notice that that modifies the timeline. The timeline is currently showing how many frames are in a single second, so here as we move from one frame to the next, you'll see that that counts up, and then at the end of our timeline, you'll see that we are at one second. So now that we have our samples set up, you can now begin adding properties which you can add keyframes to. These two buttons, Add Keyframe and Add Event, will not be available until you've added a property to the timeline. To add a property, we'll click on the Add Property button, and then we get a menu. Here, we get to choose which property we want to modify or add keyframes to. We could add keyframes to the entire object, the entire chest in this case, by using the Transform component here, and we could animate the entire chest position, rotation, or scale. Now, in our case, we just want to animate the top of the treasure chest, so in our case, we'll choose chest_top, and then we can modify the rotation, which is inside of the Transform component, and we could add that property by clicking the plus symbol here. Now, there are a few other properties that you can modify like Is Active, and that basically animates whether the object is active, meaning enabled or not, and then you also have the ability to modify certain properties of the mesh renderer. So in our case, we just want to animate the chest opening on the top, so let's choose Rotation. Now that that has been chosen, you'll see that the property has been added to our list, and now we have two keyframes in our timeline. You can expand the current property selected, and you can drill down into the individual parts that make up that property, so in our case for rotation we have an x value, a y value, and a z value. Currently, the rotation of our x value is at -15. We can select this, and we can begin to make modifications. Now, in order to make a modification that would actually animate, we would need to use the Record button to create that animation. So now that we've looked at the interface of the animation window, let's go ahead and move on into our next clip, where we're going to learn how to actually create keyframes inside of Unity.

Animating in Unity

Animating in Unity In this clip, we're going to learn how to create basic keyframes in Unity. So let's go ahead and go to our scene view, and with the chest selected, let's hit F to frame in on that object. Now that we have the object selected, we can begin to animate the individual properties that we've set in the animation clip. So to get started with this, let's go ahead and hit the Record button. Let's select the object that we would like to animate. In our case, we want to select the chest top. You can do this from the hierarchy view, or you can continue to select right here inside of the scene view. Now, with this selected, we can create keyframes a couple of different ways. We could do it right here inside of the type-in of the Transform component, or we could do it interactively using the proper tool and rotating that open. Now, in order to get started with this, you will need to make sure that you are currently on the correct frame that you would like to animate. So here you can see I'm on frame zero. I don't necessarily want to change the start position of the rotation. I actually want to change it to the end, so over time, it's going to go from a closed state, and it's going to travel through to where it's completely opened. So let's make sure that the time slider's at the end of our animation. Let's go ahead and grab the x-axis, and then left-click and drag that to where it's at the open state that we desire. You can orbit around just to see exactly what that looks like, and this feels pretty good to me. So once we have animated that, we can hit Play to preview what we have so far, so you'll see that's it's going from the closed state to the open state, and then it loops back around to the beginning of the animation. So that's how we can create some very basic keyframes. Now, we might want to add a little bit more life to this opening and closing. We could do this by creating some sort of bounce to where once it gets to the end, it bounces open and the lid kind of bounces a little bit. So let's go ahead and go to, let's say frame 25. At this frame, I'm going to cause it to overshoot a little bit and come back to this resting position, so I'm going to push that back a little bit, and so if we play this now, it'll look like it's opening and then coming to a point of rest. This is the follow through animation principle, so this allows you to create some sort of life in your animations and makes it a little bit more interesting. Now, this is very basic, and something still isn't quite right. We could continue to add a bunch of keyframes to get it exactly the way that we want it, or we could utilize curves inside of Unity, so let's take a look at those next.
( miễn phí đăng ký cho thành viên trong thời gian thử nghiệm )
// //