State of the Game #9 : Using Procedural Generation

Continuing on our work from last week, we now have a working system for procedurally building a M.A.V. unit. I have attached a short video below so you can see it in action. Please note, it is not 100% finished and is currently limited in the designs it creates due to the low part number.



Testing out the new generation system for creating M.A.V.’s on the fly based on a few settings.



So here is what is going on under the hood of this system.

We have a basic loop that looks like this:

  1.  Analyze what our goal is
  2.  Analyze what we have
  3.  Rank the parts we have
  4.  Rank the open slots we have
  5.  Try to place the part, from best to worst
  6.  If we can’t add a part, we are done.

Analyze the Goal

For any generation system, we have to have a measurable goal. In fact, choosing the right goal is one of the most important parts of getting the system right. On M.A.V., our goal is 4 separately weighted categories : Defense, Speed, Range, Firepower. These are created in a way that makes them easy to expand (Cost is already planned, once we have a money system). Again, these goals are individually weighted, meaning they can all be a full weight (a ‘balanced’ M.A.V. will be created) or all at 0 weight (a completely random result). This category system is as designed to be very user friendly in allowing them to have a M.A.V. created that matches their play style. Someone that wants a Heavy sniper would slide up ‘Range’ and ‘Defense’ and lower ‘Speed’. ‘Firepower’ would adjust how parts are allocated between defenses and weapons.

Analyze What We Have

So now that we know what our goal is, we have to determine how good of a job we are doing at getting there. In this stage we actually go through the parts that we already have and total up the ratings on each Goal area for each part. We then normalize these results and subtract them from our original goal. This difference in goals becomes our new goal set. We do this so that we can generate negative ratings in case we have too many parts in one area.

The ranking System

This is the part of the system that will be continually tweaked. Here we look at the stats of each part and use a formula to create a ‘Rating’ number. These numbers are only relative to each other, but small changes to your formula have a large impact on the overall generation system. We actually separate the ratings by part so we can generate more uniform numbers by applying different formulas based on the part type. A great example is the ‘Firepower’ category for weapons vs. cockpits. With weapons, the ‘Firepower’ rating is heavily weighted towards damage per second, as the more damage you can do, the higher the ‘Firepower’ rating. With cockpits though, they don’t really have anything that we can rate. We could just assign a ‘0’ rating and move on, but this doesn’t create designs that can rival a human player. So, we take a minor area of the cockpit, the weapons settings, and use that to generate the ‘Firepower’ rating. If you can hold more weapons and fire more weapons together, this will increase your Total damage per second, and therefore your ‘Firepower’ rating. Tweaks like this help build harmonious M.A.V.’s and is really what separates procedural content from random content.

Find a place to put it

So once all the parts are rated we apply modifiers to the rating based on where we can place the part at. (Note, we prune parts out in the previous step that would cause the M.A.V. to go out of validation, i.e. overweight, to many parts, etc..) Again, this stage like the last has large impacts on the overall generation. Some of the modifiers we use are, increase the rating of a large recoil weapon the closer it is to the center (this reduces the recoil effect), or weight the cockpit a bit higher if it’s going to be attached to the legs to get a more ‘traditional’ mech appearance. Once we have all the part/location pairs rated we move on to the next step.

Try to place it

This is the area we ran into the most roadblocks with, mainly because of how Unity handles it’s physics. At this point, we start at the top of our sorted ratings list and see if we can complete the placement. We do this by checking for any collisions between the parts and if we do get a collision, we throw out that ranked pair and move to the next best option. If we don’t have any more ranked pairs left in our list, that could mean a few things. Most likely, we have reached a limit in our design (weight limit, part limit) and all the parts where removed before rating them could happen. Also possible, we have added a combination of parts the make it so no part can be fit without colliding. There are 3 routes we could take at this point, 1. If the M.A.V. is complete enough, call it as done. 2. Wipe the whole M.A.V., change the end goal slightly, and rebuild. 3. Selectively remove a few of the ‘worst parts’ and continue building. Right now, we only take approach number 1 and this leads to the rare case of an invalid build being put out (Most of the time missing a cockpit). Implementing option 2 or 3 will eliminate the invalid builds but at the cost of slightly changing what the user wanted. We are looking into a 4th option, which would start a new build, but with slight tweaked rating formulas.

Well those are the main points of our system for building the M.A.V’s.


Leave a Reply