Unity – Building Geometry for Prototyping Levels

      Comments Off on Unity – Building Geometry for Prototyping Levels

During the prototyping phase of game development it’s common to use placeholder graphics in place of a more permanent set of art for production use. Unity’s standard assets come with a nice set of prototype geometry for use in level design which includes a floor, wall, stairs, and several varying shaped cubes. These simple shapes are well and good, and while the core of most levels are comprised of simple shapes like these, no level designer is sitting around putting levels together one panel at a time.

Out first step will be to put together some simple reusable shapes that we’ll use to build our full level. My latest project is a sci-fi game in which the player is on a space station of sorts, so I’ll be using that theme for my example. First things first, I need a corridor section I can use to make the main layout. After that I’ll need to make a few rooms that the corridors will connect. A corridor is comprised of a few other reusable pieces, such as long walls, a corner segment for turns, and maybe a bulkhead segment to break up long straight stretches.

If you’re following along, please make sure that you have imported the prototyping package found under the Assets -> Import packages menu within unity.

To start with I need a small and long wall segment. For each piece we create our first step will be to create an empty game object at 0,0,0 position and rotation. This object will contain all of our child pieces that comprise our particular section. I’m going to call my game object WallShort. Next I’ll add 3 of the wall prototype shapes found in the imported prototyping package as children to my game object. Make sure all 3 are at 0,0,0 position and rotation.

One wall will be at the center staying at 0,0,0. The other 2 will go on either side of that wall creating a 3 segment wall. Now, you could just update the coordinates manually, since the textures that these prototypes are comprised of 1 unit blocks, we know that the wall is 6 units wide, so we would only need to adjust the x coordinate to + and – 6 respectively.

This is a good opportunity to use vertex snapping to position objects in relation to one another quickly. This will be hard to describe in text but I’ll try to do my best. Vertex snapping is engaged when you hold the V key down while you’re in a translation state with an object. To start we’ll select the object we want to move, one of our side walls, and make sure we’re in translation mode so we’re adjusting the position in the editor. Move the object to the side a bit so that they don’t all overlap with one another. We need to select an individual corner of one of our walls, and if they all overlap the editor won’t be able to determine which objects corner you’re trying to get. Hold down the V key and with your mouse select the vertex on the model that you want to have line up with a vertex on another object. In our case we’ll move this object to the right of our center wall, so select one of the top left vertices, either front or back. Click and drag from that vertex, to the vertex that you want to align with, in our case, the top right vertex of the center wall, the same front or back depending on what you chose before. The selected wall we moved should snap into place with whatever vertices you drag over while moving. Once the alignment matches what we want, release V and the mouse button. The models should now be perfectly aligned with one another. Repeat the same with the other wall onto the opposite side of the center wall and we should have a perfectly aligned 3 segment wall. That root game object should now be made into a prefab for easy reuse.

Next up we’ll create 2 corner segments, an exterior and interior corner segment. The process will be largely the same, the only differences being the shapes we’ll put together. For the external corner I like to use the JoinOuter prototype object and 2 wall segments. The result I went with looks like this.

You could use this for an interior corner section as well, if you like the sharp corner on the inside of your corridor, but I’d rather have the flat edge face inward so I flipped the walls around so they look like this:

Naturally you can form these pieces however you like, this is just what I find aesthetically appealing.

Our last piece for our core structures will be a small bulkhead section to connect straight walls together, so the hallways we make won’t get repetitive. For this we’ll take a wall segment, and the JoinMid piece. We’re going to put the join mid piece against the middle of the wall like so:

Now that we have these pieces we can start to put a sample level together. First things first, we need a floor. In the prototype assets, we have a prefab FloorPrototype64x01x64. This makes a decent floor that can be scaled out to match whatever size you want. For the sake of my example I’ll scale it to 2 on the x and z axes so I can have a bit more room to work with. Using the parts we’ve created and the skills we’ve established with vertex snapping we can easily and quickly put together prototype levels for testing our game mechanics and working on the level design.