Sunday, December 1, 2013

Showcase : Defendable Walls (SC2)

Defendable Walls is a mod I made for Starcraft 2.  Messing around in the editor, I discovered a set of doodads added in HotS called Defensive Walls.  They were a set of modular walls that could be pieced together, giving a defensive position as well as a walkway on top for defenders to stand on.  I quickly started using them in my map, but soon discovered that they'd never been finished and that there were several problems with them.

(If you don't care about the technical work behind the mod, and just want to see it in action, there's a video at the bottom of the post)

1) Not all rotations were supported.  Using the walkways on top of the walls were enforced by custom footprints, but rotating the doodads often messed up the footprint, allowing you to walk through the wall.

2) Not all the models had been finished with collision boxes.  This meant that units walking on some of the walls would be in the model instead of on top of it.

3) There was an interesting set of models that merged with cliff edges, but these weren't compatible with the rest of the walls, meaning they'd always hit a dead end.

So I decided to fix these problems, as well as extend the concept a little further.

1) To solve the problem with rotations, I made a bunch of additional footprints that covered the possible rotation values of various pieces.  People using the doodads no longer need to worry about rotating the pieces and instead just need to choose the appropriate doodad.

2) The collision box problem was slightly more difficult to solve.  Opening the models in a 3D editor wasn't possible due to Blizzard's proprietary format, so I had to resort to other measures.  The SC2 editor has an option to create visual models as addons to placed units/doodads.  So when faced with a model that didn't have a collision box, I'd take a working model similar to the broken one, scale it to overlap perfectly with the other model, and then set it to be invisible.  When playing the game the additional model wouldn't be visible, but the collision box would still work, making the unit stand on top of the wall!  The one down side to this is that in the editor the models don't appear as invisible, causing them to look a little chaotic.

3) Fixing the cliff merge pieces led to my favorite part of the mod, the fact that every wall works exactly like a cliff would.  In SC2 cliffs are used to gain an advantage.  If I'm on a higher cliff level than you, I can attack you without fear of being attacked back, unless you bring a unit onto the same cliff level or bring a flying unit to give vision.  Cliffs also allow for interesting units called jumpers, which can hop up and down cliff levels.

I quickly took a merge model and gave it a custom footprint (previously they'd been implemented without one, being treated as a Terrain Object, the details of which I won't go into here).  The first problem I ran into was that the cliff the wall was placed next to would still be solid, making it impossible for units to walk from the cliff onto the wall and vice versa.  I added a "Ground" patch to the footprint, which overrides any pathing it's placed on to be pathable.  This overrides the footprint of the cliff, allowing units to walk straight over it.

The next problem came with vision.  Though the unit could traverse the cliff edge, it still counted as being a level lower until walking onto the higher level.  So you'd visually be up on a wall level with the cliff edge, but not able to see onto the cliff until you crossed the border.  The solution involved the "Placement Apply" layer of a footprint, that gives different options to change how the terrain under the footprint is treated.  One of the options here was "Boost Cliff Level" which allows me to specify a different cliff level for every cell that has this attribute.  I took the "Ground" pathing I made earlier, and applied this attribute to be one level higher than where the wall was sitting.  This meant that while a unit was on the wall, they were a cliff higher, giving them vision of that same cliff level!

I then took this a step further.  Another interesting option in the "Placement Apply" layer, is the Blocks Vision modifier which (surprise surprise) blocks vision.  If the unit is one cliff level higher than the vision blocker, it can see over it.  So I took the footprint of the walls and added a level of vision blockers around it (the part of the walls that couldn't be walked on).  This allowed the walls to be treated as cliffs in the vision blocking sense, where to see over them you'd need to be on that cliff level.  I also found that if I set the "blocking" part of the footprint to cliff rather than unpathable, this would allow units like Reapers to actually hop onto the walls (since the inside of the walls were technically a cliff level higher).  This is my favorite addition to the mod, and allows for some interesting gameplay opportunities.

One last problem I had with the cliff merge models was because of how the game handles the height of units on different terrain.  The game looks at the center of the unit, the terrain it's sitting on, and  then raises the height of the unit to be on top of that terrain.  The way the merge models were done, in order to position them on the edge of the cliff, the center of the model would actually be on the cliff slope.  This would cause the model to rise up slightly to where it didn't line up with the cliff anymore.  I solved this in the same way I solved the collision problem.  I made the doodad nothing but an invisible model, and then offset the footprint.  I then attached a similarly offset model addon, which was the actual model I wanted it to be.  This allowed the center of the doodad to be far enough away from the cliff edge so that it didn't gain any height, while still placing the model on the cliff edge.

All in all, this has been a long project (easily over 100 hours) but I've learned a lot about the SC2 Map Editor and had a lot of fun.  I'm excited to see what maps people make with the mod, and the interesting uses people find for it!

If you'd like find out how to implement the mod, as well as the download link, see this post on SC2mapster:

No comments:

Post a Comment