Skip to main content

4 walls and a floor.

 4 walls and a floor.

Those are the basic options when creating a room in a game. Of course, one or more of those walls could have a door. And some rooms might have pits, stairs, secret doors or other features.



A room is made up of any number of tiles laid edge to edge. What is important is how those tiles are combined to create the room.

We might construct our room taking in to account each neighbor, including diagonals. This is just making a rod for our own back though, and results in lots of tiles and much more work. I've tried it in the past and the result is not any better that what I'm going to describe here, more work seldom results in better results, we need to find the optimal solution. With that in mind we only really want to look at the tiles in the cardinal directions.

In that case a tile is made up of 1 square with 4 neighbors, that makes 5 components...

Cardinal Tiles
 ...but with a clever bit of offsetting we can make one of the neighbors the original square. That means any that any tile has just 4 components.

Offset Tiles

If you have only walls and floors you need only 16 different combinations (4 to the power of 2, or 4x4) to create any kind of room. If you also have doors you need 4x4x4, or 64 combinations. If you want to add corridors, pits, stairs up and down, secret doors and other features you start getting in to impossible levels of combination. Of course it's not just straight numbers, some combinations are impossible and can be discarded, but it's still a huge number of required tiles.

Using a set of rules can help, so that further combinations are impossible; for example corridors can only be bordered by corridors or doorways or doorways can't be placed in the corner of rooms and doorways can't border other doorways. But it still leaves a lot of work to do. Also as I started to put together art assets for the tile sets I was very unhappy about how they looked, every thing had to be exactly square to fit together, negating many of the advantages of the new system altogether. There was no way to know what a tile edge might be joined up to, so there was no way to get a pleasant transition. How can we get around these problems?

The solution is actually quite simple, we just use layers.

Layer 1:
  • Floors and pits.

Layer 2:
  • Walls, open spaces (which could be either pits or floors) and doors. (with rules to state how they can be combined). Walls can be corridors, but as above they can't mix with regular walls.

Layer 3:
  • Overlays. These can be anything, but for now I'm just using bridges as a test case. 

The layers are added one at a time and parented together, so that any visibility checks will make the whole stack visible or invisible as needed.
The resultant tile set looks something like this:


The bridges now are overlays and are added to pit squares. Overlays need to be handled differently to regular tile parts, they don't have an offset, so they are placed using a different algorithm (The cardinal tiles picture above show how).

I hope to write an algorithm to get the walk mesh directly from the combination of tiles rather than placing the parts and then "reading" the level to get the walk mesh data. This has a lot of benefits, such as being able to check a level for walk-ability during generation, and also being able to load the level in chunks, reducing loading time considerably. Again it'll be handled by getting the walkable tile data in layers and then using layer masks.

Anyhow, the current result looks like this:

As a bonus I've also added some code to place an "error tile" whenever the rules are broken during placement. This gives visual feedback about what you can and can't do.

Still needs some more work, perhaps I'm going to make doors and stairs as overlays like the bridges, or maybe not. I'm not sure yet. I'll try it and see how it feels.

Comments

Popular posts from this blog

Automating Level imports from Blender to Godot

  Recently I've been making some levels in Blender an importing them into Godot. There are only about 7 or 8 shaders for each level, not counting dynamic objects which will be added later. But to improve rendering performance, it can be a good idea to split the meshes up into sections. At that point you might be faced with a list like this: Or it might be even more chaotic, if you didn't use simple names for the objects in your level. So it can take a long time to sort out all the meshes, make them unique and add textures and so on. Blender imports with simple Blender textures, or with placeholder materials. This is sometimes OK, but if your Godot shaders are very different to those used by Blender, it means applying new materials to every mesh object in the level when you import the scene. I found that during the design process, I was importing and readying a level several times before I was happy with the final layout. So at first I was wasting a lot of time. In Blender, I us

Upstairs / Downstairs.

I've decided to make my prefabs multilevel. Later this should allow me to add pit traps and other great stuff. It also makes it easier to line up stairs so that you can exit them on the same co-ordinates where you entered them. The prefab editor is pretty much finished, it just needs some code for loading up prefabs from a saved dictionary, so that they can be checked or edited. The entries will need to be forwards compatible, so I'll be loading each tile and then translating the indexes to a new array, that way if I add extra indexes or extra info (like traps or puzzles) I'll be able to update existing prefabs to work with the new standard. Click for a video.

Make your game models POP with fake rim lighting.

I was watching one of my son's cartoons today and I noticed they models were using serious amounts of simulated rim lighting . Even though it wasn't a dark scene where you'd usually see such an effect, the result was actually quite effective. The white edge highlighting and ambient occluded creases give a kind of high contrast that is similar to, but different from traditional comic book ink work. I'll be honest, I don't know if there's a specific term for this effect in 3d design, since my major at university was in traditional art. I learned it as part of photography. You can find plenty of tutorials on "what is rim lighting" for photography. It basically means putting your main sources of light behind your subject so that they are lit around the edges. It can produce very arresting photographs, either with an obvious effect when used on a dark subject ... ..,or as part of a fully lit scene to add some subtle highlights. See ho