- Animation is a vital part of crafting a game and we can bring in animation from any number of sources or create it natively here in Unity. I brought in animation from both 3ds Max and Maya and we've seen it in our meshes on the engine and crane. Now I'm going to segment that animation and get it ready for importing into mecanim and triggering when I have a game event. I'll go into the meshes folder and into the machines. In here, we've got our crane, engine, gantry crane, train track and an arm.
I'll pick the "Crane_01" and we can see in here in the animations section of the inspector, that there's an animation on it. The crane swings over and the hook follows and then the crane waits and swings back. This is actually imported as one large animation called "Take 001" from frames 1 to 240. What I want to do is to segment this out and to do that, I'll take a quick look at it in Maya just to see where that animation really is. Here in Maya, I've pulled up my crane and we can see when we select it, that it's got key frames on the timeline for both the base and then the bones.
What happens is if we scrub on the timeline, we can see that the crane swings over and the hook swings back by frame 90. Then the next animation begins at frame 100. So I've animated two different sections in here I want to use and I've left a 10 frame space between to have the ability to have a little bit of room to move in the editing. Back here in Unity then, the first thing I'll do is take that take called "Take 001" and re-name it to "SwingForward". I make a habit of re-naming those takes so that there's not two objects with a default name of "Take 001", for example.
Because it's very easy to call something by default in a script and have a whole bunch of things animate that you didn't intend. Now take the frame count down. It starts at frame one, the first part of the swing, and I'll end this at frame 90. This reduces down that time, so in this case, it's running 3.7 seconds at 24 frames per second. Then I'll make another take. Clicking on the "+" under the "SwingForward" clip and making a new take, "Take 001" again. I'll rename this new take to "SwingBack" and this new take will start at frame 100 and end at frame 190.
I'll test it out, previewing and making sure that works. The crane swings back, the hook follows, and it stops. I'll give it few more frames, trying frame 200 in here. That's better. There's time for the hook to actually settle in. As you can see, I left myself a little bit of time in here to be able to play with it. We wanna make sure that this animation looks good when we segment it. So when you animate, leave 10 frames between for example.
That way instead of exactly trying to go from frame 36 to 37 over two clips, you have the room to say this first one extends out by a couple of frames for the object to sit. In this case, I wanted to make sure that the swing forward and swing back had space. That the object, the crane, had time to come to a stop completely and hold before the next animation kicked in. What you may find is that sometimes animations need to look rather clipped in order to blend. Whereas other ones need a little space. Something happens and there is a pause.
And this really depends on what you're doing. When I've got this, I'll scroll down and click "Apply" and I'm ready to look at the engine. I'll click on the engine in the meshes and we can see that this engine has a startup and then a run. It starts up, going backwards and forwards, and then runs one complete loop. Maybe this is a hit and miss engine or something that lopes and it takes a minute to start and then will run in fits and starts, bringing some life to it versus a constant animation.
What I've done in 3ds Max then, is use wire parameters to rig the big and the small wheel so the small one rotates at three times the speed. I figure that the conveyor belt material I'm using is streaky enough, I didn't actually need to animate the belt. And we'll take a quick look at this in 3ds Max to get the frame times to segment this animation into. Here in 3ds Max, I've opened up my "Engine01.max" file and we can see in here, that I've got the big wheel, the small wheel, the belt and the housing, we'll call it, the actual engine. This just needs to rev up to bring some life into the game.
It's more of an ambient animation. We'll simply start up, maybe when we're close, maybe almost at random. What I'll do is take a quick look, then, at the big wheel because that's actually where the animation sits. We've got rotation key frames down here on the timeline. Because that small wheel is animated via wire parameters in here at three times the speed of the big wheel, there's no actual keys on it. But as part of the export process, those came across that animation. I'll take a look at this and I'll look in the track view to get the values right on the keys.
Here in the curve editor then, I opened it up and flown it out. And what we can see in there is really that this animation exists from frame zero out to frame 80. That in this case, this rotation, frame 50 here, with a value of -720, and frame 80, with a value of -1080, is actually where that entire revolution sits. Before that, this jumpiness is the engine starting up. Maybe it's a hunt and idle, or a loping engine, or a hit and miss or something similar and we need that motion to really bring some life in.
My thought then, is that this animation will end at frame 47. There's my complete rotation. From there, at frame 50, we'll start up the actual revolution around. And I've purposely let that curve fall off here so it will kind of hunt and stop. Rather than simply a constant rotation, I wanted this to have some character to it so I let it fall off here, figuring that although it goes in a complete circle, we'll see it come and go in this animation and bring some life in. So remembering frame zero to frame 47 as our first segment, and 50 through 80 as the next.
Here in Unity then, I'll name this first take, "StartUp". I'm using camel case, intercaps in here with the U, to make sure it's a discrete name that won't register in normal Unity script. Then, I'll segment this, ending this first animation at 47. I'll add in another clip, clicking on the "+" and renaming this next take to, we'll call it "Lope". And "Lope" will go from 50 to 80 so I have a precise timing.
This way, if I loop "Lope", I'll get that complete cycling in here and I'll test it out, playing the preview. Holding "alt" and the mouse wheel, or "alt" and the left mouse, dragging around, I'll hit play and there's "Lope" looping. Depending on the character of what you've got here, you may want a smooth looping engine, or something that rises and falls. It's up to you how this is to be animated. As the overall look of this factory is borrowing a little bit of steam punk and industrial revolution, we'll call it, or something in there, I wanted this to hunt and idle.
To not be absolutely modern perfect, so I let it loop. "StartUp" then, as the name suggests, lets that engine, well, start up. Kinda going forward and backward a little bit to get going. Now that I've got these in, I'll scroll down and hit "Apply" and those two pieces are segmented for use in mecanim. What we can see here if we open up the engine, aside from all the elements and meshes in here, is I have two discreet takes, "Lope" and "StartUp", as unique objects that I can call in a script or bring into mecanim and set as animations to go between and transition.
The same is true for the crane. That once we take these animations and break them into clips, those clips are discreet named objects that we can call and use separately in mecanim to bring life into our game.
Released
6/24/2015- Setting up the project
- Creating a player controller
- Importing assets, including models, audio, and textures
- Generating colliders
- Creating prefabs
- Applying materials
- Creating animation
- Designing a basic game level
- Lighting the level
- Creating particle systems
- Adding audio
- Building the game for desktop or mobile deployment
Share this video
Embed this video
Video: Segmenting imported animation into clips