Into the Wall – Cave Bricks

Against the Wall - Inverted Cave BrickLast weekend I was with relatives in Austin, Texas. Not much of a vacation for me, especially since we were on the outskirts and did not go out much. No matter, I got a ton of work done with the game.

After two days of solid work, I created inverted "cave" bricks. Rather than move out from the wall and into the sky, these bricks move into the wall, forming recessed shelves. This brick type would break how the game world was originally programmed, so a ton of work was needed to get them to work.

I won't keep you in the dark about what I did, but this will be a bit technical: The wall is divided into small grids called "chunks", each 64x64 meters in size. Each chunk has one box-shaped collider which covers collision for all the bricks that are flat on the wall. Cave bricks would require me to punch holes in this collider, which really isn't possible. However, the scripts that detect, highlight, and interact with bricks all require the box collider. Solution: If the chunk generator finds an cave brick, it turns the box collider into a "trigger," thereby removing normal physics collision but allowing the brick manipulator to find bricks on the wall. The game then generates a complex "mesh collider" that is based on the mesh used for the chunk's bricks, only with holes where the cave bricks are. This mesh is placed right on top of the trigger and is used for physics collisions with the player and other objects.

In the process of solving some problems with cave bricks, I had to invent "persistent bricks." Normally whenever a brick is flat against the wall, it has no collision or scripts of its own, it shares all of that with the chunk that it belongs to. Special bricks would become inactive as a result. For example, bounce bricks would stop working while not extended. The solution was to add a function to the bricks that would prevent them from being assimilated into the wall. Cave bricks have special scripts that would be lost if they ever merged with the wall, and this prevented that problem once and for all. Also, bricks that surround the cave bricks would have to be persistent to ensure that their full geometry is drawn when flat against the wall. Otherwise, only the front face is drawn and the cave bricks would expose the undrawn areas.

The whole process was actually much more involved than that, as issues kept popping up that required solutions. The most typical problem was the frame rate dropping because of too much memory being used to generate all of the cave bricks, the geometry of the persistent bricks, and the mesh collider. I eventually whittled it down so that now the performance cost of a chunk with cave bricks is only a little worse than a normal chunk.

Since the weekend, I redid the cloud system so that the meshes are procedurally generated and all use a texture atlas. This will save a bit on performance. I also created bricks that auto extend once retracted, fixed a bug with the cave bricks and optimized their generation, and compressed the brick texture atlas so that it runs faster, using less memory. That's just about it for now. Will keep you all posted!

EDIT: Added the image and adjusted the title, and elaborated more on persistent bricks. I've also decided to rename the inverted bricks a "cave bricks", which is a bit more descriptive.

Posted in Uncategorized
3 comments on “Into the Wall – Cave Bricks
  1. zikron says:

    Love the cave brick idea, that should add a lot more complexity to the game. I also find that referring to the areas as "chunks" brings back fond memories of Minecraft. I share the same high hopes for this game as I did the aforementioned.  When I visited my family in Arizona, I was in a similar scenario as you were here and found that without all the distractions I was able to focus. I designed and built a rather complex website while I was there. Would love to see videos of these in action with commentary but seeing the complete game comes first :)

  2. Michael says:
    Notch once explained procedural generation in a blog post. There are also Minecraft wiki pages that explained the chunk format. I followed this model using a 2D vertical plane and irregularly-sized blocks. Hardest part was making bricks overlap between chunks to erase the seams, and allowing the chunks to communicate with each other. Will eventually add more random elements to the chunks so that things are not as flat. To be specific: chunk types and regions.
    And yes, productivity was several times greater when I was so secluded and away from home. Also, I found that blasting my ears with mindlessly loud techno/trance music allows improves my ability to focus.
    Will add a video at some point to explain some of the new systems. Takes a bit of time to do, of course.
  3. xzile40 says:

    Nice job!  I have high hopes / expectations for this game, and every time I say that those hopes / expectations grow. :)  I can't wait to see a update on the alpha.  I just hope that you set it up the way you did before, so that when I am not at home I can still access it.  Keep up the hard work ^.^

Leave a Reply to Michael Cancel reply

Your email address will not be published. Required fields are marked *