Procedural Generation

As a small – nay, tiny – development team, one of the biggest challenges facing us is that of content creation. We simply do not have the resources to create all of the assets that we would like for the game. It all adds up you know – a monster here, a quest there, another animation, another effect. To make all of these things individually by hand would be prohibitively expensive.

That’s why we’ve turned to Procedural Generation as a way of easing our own workload and letting us concentrate on implementing all of the features that we want.

It seems that Procedural Generation is quite the fashion these days. It often gets trumpeted by marketing as a bullet point or USP. How many titles have you seen on your Steam page that shout about their Procedural credentials? Have you played Minecraft? Are you interested in No Man’s Sky? These are the Procedural Poster Boys. Those bad boys are able to create entire planets and galaxies for you to play in – something that wouldn’t be possible using ‘traditional’ means.

What we’re doing is similar but on a smaller and more individual scale.

Procedural Generation, or PG – as I’m going to refer to it henceforth in this post – is being used in a couple of areas in game.

Firstly, we are using it for the Quests. One of the biggest time sinks we had in the development of Super Glyph Quest was the map screen and the fact that each Quest was handmade. Each Quest had a list of monsters that it would spawn from as well as an insane tech-tree that decided whether or not the Quest was available to the player at that point in time. Needless to say this was both very time consuming to maintain and prone to game-breaking errors if I got any little aspect of it wrong. Now everything has been considerably streamlined, to the extent that all we need to do is specify the level of the quest and the environment in which it takes place.

One of the most fun uses of the Quest PG was the Quest Name Generator. Each Quest has it’s own name which is derived from a series of lists featuring adjectives and nouns that can be mashed together in a traditional RPG style. It’s amazing how many ways you can combine a noun and one or two adjectives together, with an occasional ‘The’, ‘of’ or ‘of the’ for company and come up with thousands of viable quest names. The nouns are all based off the environment type – so Mountains becomes anything from Crags and Cliffs to Ravines and Canyons. Then you just throw down pretty much any adjective you can think of – The Crags of Chaos, Ravine of the Damned and so on. You can even play with the ordering – The Howling Bluff, for example.

12788280_10153267666050940_2052473216_n.jpg

As a side note, we started to realise that most of the adjectives were pretty bleak in nature, so we started adding some more cheerful or neutral ones. These were flagged as such and the generator was told to favour these at the lower levels. People will now start their adventures in places like the Singing Forest or the Cove of Smiles. We also added people or profession types into the descriptions – Hills of the Knight or Rhiabelle’s Tower. Then you can even mash all of the elements together – Parker’s Warm Morgue… okay, some names might be more successful than others.

Even before we decided to introduce more animation to the characters, we knew we had to up our combat presentation game. It needed to look better whilst at the same time being faster and less intrusive. We starting thinking about bringing on an animator to help with the effects – think of the sword effects in games like Strider, Samurai Shodown and Soul Calibur. Each of those arcs would be hand-animated in a traditional style.

But to get someone to do that would take money – we don’t believe in the “It’ll be good exposure” pitch to creatives – and that’s a resource we don’t have. So we turned to PG.

Creating procedural meshes in Unity is something I’ve dabbled with before and it seemed like a simple thing to turn it into creating arcs. Animating them, however, was an entirely new prospect.

The approach was pretty simple in the end. Define start and end locations then add a bunch of points along the way depending on how refined you want the arc to be. The basic ‘spine’ is defined by an AnimationCurve, which let’s Unity handle the grunt-work of the maths side of things. This lets me define the path the slash will follow – curved, straight, angular, wiggly – whatever really. Another AnimationCurve defines the mesh’s profile or width along its length. This is where we’d say whether the slash was pointy at each end, expanded out like a fan or straight.

The mesh is created with all of the vertices along the central spine and, therefore, invisible. As time progresses, the vertices move out in sequence to their prescribed positions based on the profile and amount of time elapsed. This gives the impression of the slash being ‘filled in’ as we go. Finally, once the sequence has completed, we gradually ‘fade out’ the slash by moving the verts back to their starting position all at the same time.

12520259_10153267665810940_70532180_n

I even added line draws in the editor that take the curve into account, making it easier for me to set up the slashes. I understand that there are better ways of setting up the curves in the editor, but these all require a much greater knowledge of maths than I have. Either way, this is the first bit of code I’ve written where I’ve actually found myself thinking that I could put it up on the Unity Asset Store for others to use.

Following the success of the slashes, I was inspired to take another crack at lightning. It works in a similar way but the reaction of the vertices is different. I still create a basic spine, but this time the arc is determined by a random number between two constraints that is re-rolled at a specified time interval. Then the individual vertices are perturbed further by yet more random numbers, giving the whole thing a jittery, crackly feel. Throw in some particles at either end and you’re really in business.

One of the things with PG is the mindset you have to adopt. The strangest thing is the feeling that you’re not fully in control. Sure, you set up the initial parameters, but after that, you’re just holding on for the ride and seeing where it takes you. If you’re a bit of a control freak, this is one of the biggest hurdles to get over. But once you do and you start to embrace the emergent nature of it, brilliant things can happen.

You’ll start to look at the results in a new way or find new ways of using the existing system. Using it in ways that you didn’t think of at the start.

By making the slash spine AnimationCurve a straight line and the profile a bit angular, we’ve got thrusting or stabbing attacks. By making the slash fan out, we’ve made our Goblin Witch sweep at the player with her broomstick. Reducing the jittering in the Lightning generator gives us beam lasers.

 

12726172_10153267665460940_440581615_n.gif

The possibilities are endless. Which is kinda the point.

– Alex

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s