Join Adam Crespi for an in-depth discussion in this video Creating animation in Unity, part of Unity: Level Design.
In a game, along with the static environment pieces, we need animated assets to bring the scene to life. If we don't put life into a scene, it is exactly static and kind of dead. So what we want to do is think in terms of two kinds of animation to really add some sizzle to our game. There's character animation we'll see, both the non-player characters and possibly a third-person-player character, for example. Animating, running around the market in this case. There's also ambient animation. An ambient animation can include characters, but also includes things like, spinning fans or flickering lights.
It might include traffic in the distance, or even an animated sky, showing clouds passing by. The ambient animation is something that's always around us in the world. It ranges from wind ruffling clothing, to ripples on the water. We need to think about putting this in and where to put it in, to really add some life to our scene. I've modeled a few extra pieces here. We can see some more detailed objects, placed exactly over the white boxes for the prototype. For example, I've taken a very basic archway here and replaced it with a wall and a pointed arch. I've also put a keyhole arch in and finally a bit thicker of a standard rounded arch.
There's some additional wall elements here behind the dome. Again, the keyhole and pointed arches ready to place around the scene to bound the scene in. These are over the prototype white box elements, so that when I re-export the FBX it will go exactly in that place and be a straight replacement once through any prefabs in immunity. There's 2 extra buildings here in the scene ,these are our long store fronts,each of them has an outside shell, an inside wall,a floor,a threshold that is part of the outside shell. So there is a difference in flooring and a back door, so we can duck at the back if we need.
Beyond these there's a fan inside, I'll zoom in and take a look at it. There's a fan blade and housing assembly, a mounting and a light at the bottom. This is the kind of thing that can really add some life in the scene, just simply the fans in the room are on and turning slowly. We can also have the lights on, or come on when the player enters or even be on but flicker occasionally as if the power is pretty good but occasionally dips. We want to think of objects and where and how we're going to animate them when we're talking about ambient animation. This way, we can decide whether to animate here in maya or in unity. For materials, the things that transfer from Maya are really the placement, diffuse colour and the name.
Other material attributes are handled in unity distinctly, so materials should be animated there. For objects we can take animation over I could take this fan and animate in Maya here and export it via FBX out. But this is the kind of thing I can animate in unity quite easily and so I will do it there. Characters may get animated here in Maya, and that animation will come across separately, and then dealt with in the Mechinam animation system immunity for blending between different animations, but that's beyond the scope of this course. I've exported out the FBXs, and brought them into Unity, overwriting the originals so that they update in the new scenes I'm going to use. I'll go into Unity and see how this looks, and then bring the fan in to make it spin. Here in Unity, I've opened up Scene 04_01_ani_start from the 04_01 folder in the Assets folder.
I've also fixed my market map, downsizing that image, so it comes in and displays at a max res of 2048. I downsize this in Photoshop as well, reducing it from 4096 to 2048, to save some space. I reapply that in a material called Market Map, making sure I go in and select that texture correctly. When you rename a texture, it'll break the link needing a manual relinking so it displays correctly. Now I'll bring my storefront in. I'll go into the Imported Meshes folder.
What I've done is to create folders by right-clicking and choosing, Create Folder. Naming them appropriately so I can organize my scene. I've put all of my imported FBX objects in the imported meshes folder and this way I can have a folder seperate for animations for example, or materials or textures or even scripts. And my assets folder gets a little bit more manageable. In imported meshes I've got all of my new pieces. What we can see here is that by exporting those fbx's and positioning the object in the same place as the white, box objects, the new detailed objects such as archway A here.
Is coming across correctly with it's correct attributes here in the inspector. A scale of one colliders is on. And if we look down in the preview here, there's that detailed archway ready to place. If I've already placed it in the seam, that archway will ripple through, changing every prefab it's used in. I'll pick my storefront long A01. It's the long store with the back door. And I'll put a fan into it. First, i'll drag it into my scene,i am going to land this, and get its fan in, and then place it around. I will press f to focus and zoom in on this object, its dark because the way the sun is,the direction of light i am using.
I can put a separate light in once i get the fan in, or work in a wire frame ,i will pick my ceiling fan object, when we export an fpx its got multiple objects in it. It shows up as one object here and we can open it up in the imported meshes by clicking on the right arrow. There's an avatar, and the five pieces along with the transform. I'll take this ceiling fan and drag it into my building. It's in here but it's a little off because I'm in a perspective. I'll pull this back over and press F to focus in. Making sure i take the fan and place it up against the ceiling. One more way to do this, is go into a side or front view for example and change in this case my left view to an isometric by clicking on the word, left then i will switch over to a wire frame so i can see through the building and move it up. I will move this up and zoom in,press v to snap ,perhaps taking an over near vertex so i can zoom in more, I'll press V to snap, and snap this fan right up to the ceiling, then zoom out and place it.
It will be dark in this building, so what I also need to do is to get a light in, which I'll do by choosing Game Object, Create Other, Point Light. Now, I'll switch back to a perspective by holding Alt, and clicking and dragging the left mouse, and then changing from ISO to a perspective. I'll make sure my fan is in the scene. It's a ceiling fan prefab. And I can tell by the blue writing here on the side. I'll pull this over, and go in. Changing over to maybe textured so I can see better. And there, at least in gray is my fan lit with a temporary light. Now, I'll get this object animated.
To animate, we can choose window and animation from the top menu. The animation menu is a lot like the graph editor in Maya, or the curve editor, or mini curve editor in 3Ds MAX. Using function curves to define animation between keys, and able to interpolate them as needed. What I'll do, is open up that ceiling fan prefab and select fan housing, which is the actual object I want to spin. Here in the animation menu, first, I'll click on the animation button. What this one's to do, is add a component onto the ceiling fan for animation. I'll click Add Component.
And the component I'm going to add is a .anim file, which I'll place in the 04_01 folder. I'll call this 04_01, ceiling fan or spinning fan. This way I have a unique callable object of an animation that's separate from the object. With an FBX, those are embedded. I'll click Save, and now I'm ready to animate that fan. To make it spin, what I'll do is first pick what I'd like to animate. In this case, it's the y axis I'll be spinning on. I can press e for rotate, and add a key by clicking on the Add Keyframe button. There's a key here at zero of a value of zero.
There's no spin. I'll go over two seconds here so that it goes around once every two seconds in a slow loop. I'll click and drag on that fan and hold control to snap it. In this case, I'm watching this animation go, and we can see it cycling here as I scrub side to side. Alternately what I can do, is click in here and enter a value. There's a 360 degree animation, with tangents at linear. As it's a fan, I'd like it to loop continuously, instead of starting and stopping. It depends on the animation you'd like. If it's something like a door, for example, you might want this to open over 95 or 97 degrees and ease to a start and stop.
And you can do this by selecting the key, right clicking, and changing the tangent types. We've got tangent types of auto, free smooth, flat and broken, and also, in and out for left and right tangents. I'm going to leave this alone at linear, as I want a constant smooth motion on this. I'll close the animation menu, and now on this fan object, I've got this animation. It's called 0401 spin fan, and we can see it here attached to that prefab. What it also says is play automatically. And under Animations if we'd like we can have more than one. For example, on a character you may have more than one animation, which will load depending on what you're doing.
I'm going to change the Culling type from Always animate, to Based on Clip Bounds. This way whatever I see in the camera will animate but the fan won't be spinning if I'm not seeing it. Finally, I'll click on the actual animation. Going back in my assets folder, and into 0401. And there's that, 0401 spin fan. With every animation, we can determine a wrap mode. What this means is, how does that animation work? It's the equivalent and Maya of pre and post infinity. Or in the out of range types in 3DS Max.
I'll set the Wrap Mode for the fan to Loop. That way it loops continuously, spinning away. I'll press Play, and see how my game looks. Starting at my spawn point, zooming in to go look at the fan, and I should see it spinning in the room. Once I enter into my store, I can see that fan has started, and there it is looping. With the wrap mode set to loop and the keys at linear, it's going to sit there and, well, turn slowly as fans do, hopefully keeping the shop a little cooler. It's a great way to add, just life to the scene. Somebody simply has the fans on, and we can use different animations.
If you'd like you can even script in some randomness, so it starts at a random place so the fans aren't all, quite in sync.
Note: This course places a strong emphasis on modular construction techniques and resource optimization as part of the design process, which will help your build process be more lean, nimble, and efficient. A basic knowledge of Autodesk 3ds Max or Maya, and Adobe Photoshop is recommended.
- Setting goals for the player
- Planning the player path
- Bounding the world invisibly
- Defining player scale and field of view
- Using and joining modular elements
- Setting up prefabs
- Adding ambient animation
- Opening doors
- Making stairs walkable
- Lighting scenes