Saturday, July 11, 2015

Animator controllers

WARNING: LONG, BORING POST AHEAD

So now that I have your attention, thought I'd take some time and take a big picture look at what's currently going on with Bevontule as well as what we're shooting for in the next couple of days/weeks.

On my end of things, I decided to pretty much break everything that had been working. OK, I didn't decide this, rather it was forced upon me in the form of a botched Unity merge in which it decided to strip all of the animations from the various controllers I had worked on up to this point. An animator controller is something that essentially holds all of the animations for a given character and is responsible for... you know, why talk about it when I can just show it to you (fellas, do not try that line on the ladies... it does NOT work):


Within Unity, this is what the animator controller for say, Bodom, looks like. Or looked like. Let's be honest... something like this is not really sustainable (this is just for ONE cutscene, really) and the fact that Unity fubar'd all of the animations (literally set them all to None) was pretty much all the reason I needed to redo this thing. 

So that's what I've been doing for the past few days. It's sucked. Not gonna lie. I cried seven times. But it has been entirely necessary and will actually make things much better. I've learned quite a bit as well and am going to talk about some of these Unity concepts that have made our lives easier.

The first is the concept of avatar masks/layers. While cobbling together our animations, we have had to make due with a lot of... uh... imperfections (tamest PG word I can think of atm). For instance, you have an animation of a guy laying something down on a table, but for some reason, he decides to slide his legs in about the most unnatural way possible, while still somehow not incurring any significant medical trauma.

But, as it turns out, the part where he actually places the thing on the table is golden (his upper body/arms/head)... in fact, if I could just use that portion of the animation and leave the legs straight, I'd be one happy fella.

And with masks/layers, that's exactly what you do. You designate a layer for each animation state (one of the little gray boxes in the previous picture). For instance, we have layers for all of the major body parts: head/arm/torso/leg/hands. With a little bit of caressin' and sweet-talking, Unity can be coerced into allowing this to work. For instance, for the PlaceObject state, we have the legs/feet/root position being controlled by the Idle animation, while the rest of the body is controlled by the PlaceObject animation. The result is much more natural and smooth than it was before (previously we had just relied on people not looking at the bottom half of the screen so that they could not see the legs and/or blindfolds/duct tape.)

The other cool thing about this is that we are using the Idle animation to control the legs, but we could easily change this to another animation. For those unfamiliar, an Idle animation is basically a 'default' animation in which the character is standing in a neutral pose. (Like how you'd stand at the BMV on a hot day with lots of people... ok, this is probably more of a Pissed animation, but still.)

So if we want our characters to be sitting in a chair instead of standing, we can make that happen. And then any animation state that the character can use while standing, they can also use while sitting. Pretty cool, huh?

OK, so, I lied to you, it's not quite that simple. There is still one other crucial ingredient that is missing, and this little SOB is known as an Animator Override Controller (terse, huh?). We're gonna call this an AOC for future reference... actually, let's just go with SOB. Before I tell you about this SOB, we're gonna talk about why we need him.

Each state (any of the gray boxes up there) contains several key pieces of information: the animation clip to play, the speed at which to play it, whether Foot IK is used (ALWAYS ENABLE THIS... er, sorry, got carried away...) and a few other things. This is where we would specify the Idle animation or the Sitting animation. It looks like dis, as an example:



Easy then. We just make a whole new controller and replace every Idle animation with our Sitting animation. Woo. Time to have a beer.

Not so fast though, ya drunk bastard. Let's say we want to be able to perform these animations from other states... laying down, crouching. Let's say we want to be able to wave, but we want to be able to do it while we're walking and/or running. Maybe we want to have Bodom ride a unicycle while snorting a line of coke off the top of the accordion he is playing. (DLC anyone?)

All right, well, we'll just make a separate animator for every single... uh...situation... yeah. No, we're not going to do that. Granted, this was sadly the original plan going forward: make a different animator controller for each character and each cutscene (you'll notice the first picture refers to a AtoniaOutside animator controller.) Yeah, that's bad. Real bad. But as any real-world programmer knows, you basically do things the worst way possible until a certain point. This is the "Does-It-Work? No. Does it work now? Yes. Rewrite it." paradox.

Trust me, if we could have gotten by with having multiple controllers, I would have gladly done it. But we can't. So, the question this really forces you to ask is... is it possible to have everyone use the same animator controller? Wouldn't it be nice to just have one of those sitting around instead of having one for every character/cutscene/blood type etc?

And as it turns out, you can. (You're 2/2, Unity, on answering questions with satisfactory responses.) And we can do it using this SOB thingamabobajig that was spoken of earlier. While it does have a rather ridiculous and intimidating name, it's actually quite simple.

We make a new SOB and we say, use a specific controller. In the current redesign, we have one controller called "Generic" that contains ALL of the animations that any character can perform. We hook this up to our little SOB here, which looks like this:


As you can see, this thing contains every animation state and clip present within the "Generic" animator controller. This means that all we have to do to replace this is to change the "Idle" animations above to "Sitting". And from there, we will have birthed a character whose default state is "Sitting" and who can then perform any of the actions above from a sitting pose and not a standing pose.

The only drawback to this is that it broke nearly every damn cutscene we have made. Fortunately, there are only about five or six thus far (and I have become rather adept at fixing them). But you gotta break a few eggs to make a chicken or something along those lines.

I know that's a lot for just a small portion of our development, so we'll save the other junk for another day. Thanks for reading! 

No comments: