Friday 5 July 2013

To thwack or not to thwack



               This post is going to be delving into the murky depths of the melee combat system inside Last of the Warlock Kings.  I really wanted the melee In the game to be more than the rubbish standard you see in so many RPGs and turn based games.  You get a basic swing of a sword, and a basic pain animation plays in the target.  Or worse still, you miss, but the same attack animations play out and your sword goes through the target character – what sort of a miss was that!?

                So this means one thing – LOTS of animations.  And I mean lots.  Everything in the melee system needs to be more believable than the usual fare, so that means animations that are normally ignored.  For example, take the standard swinging the sword animation.  In a cheap and basic game – this is two animations: the swing animation and the pain animation.  Now let’s make it better – the standard swing needs a new animation for when the attack is blocked and the sword bounces off the shield.  This also needs a new animation for the victim where they raise the shield to block the swing.  Now it looks a bit naff having the sword bouncing off the shield without any reaction from the shield bearer, so we need yet another animation where the shield bearer reels back slightly from the impact.  Now we go one step further and make it possible for the victim to duck the swing (a proper miss!) and so we need another animation for that.  Suddenly one basic and simple move requires six different animations (swing, pain, duck, raise shield, attack reels from block, victim reels from block).

                Fortunately, the Unity engine recently released their new animation system called Mecanim.  The Mecanim system has one powerful advantage – state blending.  It can smoothly blend between animations with ease, or even a wide range of animations.  This gives power to the next phase of the melee system, expanding the repertoire.

                Before animation blending of this scale entered into game engines, it was a major pain to create a wide variety of moves, as each one would require animations created for it and the relevant impact/dodge/block moves would also need to be created.  This could very quickly scale to an obscene amount of animation and would bog down projects.  Now though, it’s possible to develop a system where animations can smoothly move into each other, to create strings of moves, instead of having to create a new animation for the entire sequence.

Better still, Mecanim allows for animations to play out as a blend of two different animations.  This allows me to create tow swing attack animations – one that swings high and aims for the head, and one that swings low aiming for the feet.  Now when the player character is confronted by a dwarf or other short opponent, I can set the blending amount to 50% and the animations are swinging at the dwarf’s head height instead of a human head height.  Some simple math and the animations are automatically created for victims of any height (within reason!).

                The same can be done for the swinging animations, the blocking animations, and the impact animations.  Now I have a whole variety of moves possible for just a handful of animations.  We can then take this one step further.  I create second versions of the attack animations, ones that swing from left to right instead of right to left.  Throw in another blending of animations, and we have an even greater variety of standard attacks.

                Finally, we make it so each attack can blend smoothly into the next attack, and entire strings of attacks swinging the sword in a variety of ways are possible, and each one smoothly moves to the next to create a dynamic, flowing string of attacks, blocks, dodges, and parries.

After the moves were working nicely, I considered blood.  Most games are content to give you just a standard blood spurt when you hit a target.  This is dull, and this is the 21st century - we can do better.  To this end I devised a system where the game tracks the motion of the weapons as they swing around hacking at the victim, and the blood spurts will erupt from the point of contact and travel in an appropriate direction with the weapon.  It just looks much nicer when you see a sword slice through a monster and see its blood spray outwards along the swing direction.  It’s simply more satisfying.

                Couple all of the above with the data driven approach (to be covered in detail in a future post) and a complex, varied, and dynamic melee system is born.  The data driven approach makes it so easy to add new moves, that I am free to create a wider variety of moves, and more complex moves than most games even attempt.

                Here’s a video from very early in the development of the melee system, where you can see moves stringing together.  In this video the animations are still rough and the blood effects were only basic.  Improvements have been in many areas of the melee system since this video was made.


No comments:

Post a Comment