Featured Blog | This community-written post highlights the best of what the game industry has to offer. Read more like it on the Game Developer Blogs or learn how to Submit Your Own Blog Post
Trying out Skeletal Animation for Top Down Characters
Making 2D top down characters for a 2-player game, how hard could it be? Pretty hard but not impossible as we found out in the course of four months developing Goon School.
Making 2D top down characters for a 2-player game, how hard could it be? Pretty hard but not impossible as we found out in the course of four months developing Goon School. What follows is an account of the roller coaster ride the team at Zebu had building these little thugs. (This blog post appeared earlier on Zebu Games)
The Concept
Initial concept - Tug of Words |
It was early September when I first showed a prototype to the rest of the team. Aptly called 'Tug of Words' it had two players playing against each other on the same screen. The objective was simple: be the fastest to uncover a hidden word and 'tug' it towards your side of the screen. Crossing a line meant you won. There were few issues with the real estate, but the game mechanic worked. We had to now figure out how to make the game more lively.
The past two games made by us were very much on the minimalist side and so I made my case for making this one as un-zennish as possible. There would be player avatars that took some action with every word uncovered. Debates raged on what this action could be. Everything from cowboy shooters to raccoons to rope tugging minions were put on the table. But it just wouldn't fit. The first few prototypes failed miserably to engage players. Most wouldn't even notice the extra action. A week went by, then a month without any breakthrough. Finally, it dawned on us that we were too fixated on making a realistic
Another failed prototype called backyard wars |
connection between what the players did with the letters and what could happen in the game world. Not necessary we realized! Anything can happen in a cartoon, so can in a game!
Since all it mattered that a player relates their tile tapping action to a consequent avatar response we needn't have the two physically linked. A fairly simple story ensued: Two street thugs pitted against each other with the faster player triggering his thug to land a punch on the opponent. Partly inspired by the (failed) 1984 NES game Urban Champion, the aim would be to 'push' the opponent towards impending doom, say a manhole on the street.
Easier Said Than Done - Sprite Sheets
All pepped up, I set out to create the artwork for a street boxer in top view. I was no artist or designer but with the help of a cheap graphics tablet and the wonderful painting suite Krita, I managed to get a crude walking, punching, and tumbling character at 1 frame per second. Not bad for a guy who applied most of his sketching skills to flowcharts and block diagrams.
Sprite sheet of the home made street boxer
It was the first step in the right direction after a bad month. After getting the team and our inner circle of friends and family excited by the fresh prototype, we decided to go with the thugs and goons story. At this stage certain requirements were already beginning to come out:
The characters had to be true top down (slight tilt was tolerable) and not isometric as two players would play on opposite sides of the screen.
Every hit would move the characters a fixed distance till the losing character fell into a manhole or a pool.
The movements would be completely controlled by animators, no physics would be applied. This was because movements were fixed and deterministic.
The recoil response had to closely match the hit action. E.g. a hit to the head would have a different response than a hit to the abdomen.
Layer orders had to be changed dynamically to ensure that the hitting characters arm/weapon were drawn above the hit portion of the opponent.
Close combat action meant the animations and artwork had to be detailed to the level of a side scrolling character.
Implementing the animations in Unity, our game engine of choice, was fairly straight forward. Mecanim handled the internal animation states unique to a character but a standard interface was defined to ensure compatibility between different characters. More on that later. The animator also controlled external variables to control movement, for example to sync with walking motion.
One animation & artwork requirement |
Sprite sheets gave a lot of freedom to the character behavior but came with a big drawback: creating the actions at 24fps needed enormous effort which no single artist that we approached was willing to do (the artwork being in top view made it even harder). With a minimum of 5 poses, there would be hundreds of high res memory hogging sprites. We had to drop this approach.
Spine or Spine-less
Skeletal animation for 2D characters is commonplace in side scrolling games, but I found very few games using that technique in the top-down games. One notable example is the heist game, The Masterplan. The robbers in the game consist of body part sprites layered in the z-order and hierarchically parented (e.g. hips->torso->head->cap). There weren't many detailed movements but it gave me the confidence to try out top down skeletal animation. To begin with I got the free edition of Spine, the de-facto skeletal animation toolkit and tried tinkering around. Spine boasts of some wonderful features like character skinning, animation blending, free form deformation among others. It looked like the perfect tool for the job and I almost bought it at first sight.
The Spine skeletal animation toolkit |
But as I delved deeper into the workings of Spine and skeletal animation in general, several challenges cropped up:
Unlike their side view counterparts, top down characters have a lot of motion which is perpendicular to the viewing plane. E.g. head looking up and down, arm swinging, tumbling etc. Animating such motion only through affine transforms (translate, rotate, scale) is quite difficult. A combination of sprite switching, affine transforms, and mesh deformations is required.
Bone manipulation becomes hard as most of them are concentrated in a small area.
Many sprites had to slide under another, e.g. shoes sliding under thigh, which meant the bone joints were no longer fixed. It also meant that IK (Inverse Kinematics) could not be applied correctly.
Spine brought its own set of specific issues. The default spine animation system required a separate runtime where there were no means to animate external variables (remember I needed these variables to control the movement of the character). A 'baked' version was available that used the native Unity Mecanim system, but here the FFD (mesh deformation) capability was lost. All put together I found that Spine wouldn't be of much help, or any skeletal animation plugin for that matter. So I had to build a system from scratch.
A Bare-bones System
If we drop out the bones and IK from a skeletal animation system there isn't much left other than a hierarchy of game objects controlled by an Animator. Keeping flexibility in mind, I built a game object hierarchy with every game object having an extra child object that contained a set of sprites. This way I could combine sprite switching with regular transform manipulations.
Game object hierarchy of a character in Unity |
Each of the sprites was arranged in z-order (sorting layer order in Unity speak) such that they layered correctly over one another to resemble a human body from top view. I set the pivot points of each sprite to approximately reside on the joint of that body part. The body part sprites, of course, had to individually created by me as it was deemed too risky for an external artist to take part in this experimental system. With the initial posing done I was ready to animate life into the body.
Fun with Animation
It was my very first time animating a character and I must say the whole experience was quite rewarding. It was akin to puppetry but far more constrained. Having a hierarchy mapped to human anatomy sped up the process quite a lot. I made a total of 5 different animations (just like for the sprite sheet based character) and wired them up to Mecanim's state machine. As an added bonus I could smoothly transition between two animations (blending). The final animation ran at a butter smooth 60fps letting our first goon put up a hilarious performance.
Mecanim State Machine of 'Duh Goon'
Duh Goon hitting another
Satisfied with this technique it was now time to acquire professional artwork
Chasing The Artist
Getting the right type of artist to do the top down artwork was far harder than we expected. Most of
Goon mugshots by our Serbian artist on iStock Photo |
the game artists we approached either backed out or quoted ridiculously high prices once we showed the top view samples. We had to look elsewhere. Scouring the vast underbelly of image stocking sites we came across a few goon mugshots that a Serbian artist had put up. The cartoon-ish art style was close to what we wanted so we reached out to him. He had never worked on games before but was willing to take up the project to build his portfolio. It was a risk worth taking so we signed him up.