Friday, October 25, 2024

Procedural Buildings: Sewer Tunnels

I was watching some YouTube videos of urban exploration where people were exploring storm drains under a city, and this gave me something else to add to 3DWorld's procedural cities. I've improved basements in the past few posts by adding interrogation rooms and machine rooms. Now it's time to add underground tunnels. I originally thought of connecting these to the water (ocean), but none of the cities are close to water. Also, the water is far from the player spawn point near the center of the island. So instead I decided to connect tunnels to basement rooms instead.

I started by iterating over all of the locked ("false") doors I had added at the end of extended basement hallways and long rooms to make them appear larger. Any door that was far enough underground and had empty space surrounding it on three sides was a candidate for placing a sewer tunnel. I added a vault-style heavy metal door with a wheel handle connecting the room to the tunnel that was open to the player. Tunnels run perpendicular to the room and door in both directions and may have right angle bends in their paths. I added metal grates in the form of vertical bars near the ends of the tunnels and made the very ends black. This, combined with dark fog, made the tunnels appear to continue past the grates.

Here is a view of a sewer tunnel system under the ground with the terrain and grass drawing disabled. This network runs around the perimeter of the extended basement of an office building, but in general it can go anywhere there's available space. I may even connect tunnels between multiple buildings in the future like I already did with extended basement hallways.

View from outside a tunnel system that runs under the ground. The terrain and grass drawing has been disabled. The dark rectangle on the bottom right is the sewage quad drawn under the bend.

Tunnels have dark brown sewage flowing inside them with a randomly chosen level and flow rate. They also have smaller pipes connecting to them on the sides and thin metal pipes passing through them along the top. I added rats on the ground in some segments that squeak and run to the nearest grate when the player approaches. I also added spiders that walk back and forth upside down along tunnel ceilings. Spiders don't currently interact with the player.

Tunnels are drawn as cylinders, with quarter torus sections for bends. It actually took me quite a bit of experimentation to figure out what the correct bend geometry was. Fortunately, I had already added half torus drawing for bucket handles, so a quarter torus was simple to add. I used a concrete texture for the walls and applied the wet effect to these to give them streaks of darker color. Speaking of darkness, there's no light inside these tunnels, so the player must bring their own flashlight or candle to see anything. See how dark this is? It's completely disorienting to walk through here without a light.

Flashlight view of a sewer tunnel near the place where it connects to a basement room, with a spider visible on the ceiling.

I did add logic for zombies to follow the player into the tunnels with a recursive path finding algorithm that forms a path between the connected cylinder and quarter torus sections. These are currently dead-end death traps for the player. Maybe I should add some reward at the end of the tunnel? I'm not sure what to place here. A vertical shaft leading back up to the surface that serves as an escape path? That could work in cities where the ground above is flat.

I'm considering adding T-junctions to sewer systems. I haven't yet figured out the mathematical function needed to join cylinders into a T-junction in a smooth and clean way. I do have a T-junction where the tunnel meets the room doorway, but this is square on the doorway side. It's easier to cut a square hole into a cylinder (remove half/180 degrees of the cylinder) than a circular hole. 3DWorld has CSG support for cubes, some types of cube + axis aligned cylinder operations, and a few others, but no cylinder vs. cylinder operations. This would be a problem for vertical escape shafts as well. It would be so much easier if I used rectangular tunnels. The problem is that I already have extended basements, which aren't much different from rectangular tunnels. The main difference is the lack of sewage on the floor!

Here is an earlier video where I explore a sewer tunnel with a flashlight and candle as light sources.

The player can find both light sources in buildings. Flashlights shine further with a narrow beam. Candles light only nearby objects, but in all directions. There are no ceiling lights, shadows, or indirect lighting.

Here's another video where I added spiders to the ceilings.

I think I'm done with basements for now. I may add underground shopping malls sometime in the future if I can figure out how to do it efficiently. The next item on my task list is writing the logic for cars to navigate city parking lots. I'm sure that will be challenging, considering how difficult cars have been to work with in the past.

7 comments:

  1. Thanks for adding spiders to the sewers! Are you going to add storm drains as well? How about larger and smaller sizes? And crawling so you can explore small tunnels? I feel like crosses, tees, and Y junctions are really important for making the tunnels interesting. Could you procedurally deform the wall geometry with a noise function to make caves?

    ReplyDelete
    Replies
    1. There are many possibilities. Right now the tunnel diameter is set to the floor to ceiling height of a room so that the top and bottom connect directly and I can use the same floor stacking logic for tunnels and they can fit in between other floors. Smaller tunnels are possible, though people and the player won't fit. Maybe I could add forced crouching like I did with low attics. I do have some smaller side tunnels, but the player can't enter them. I may add vertical shafts up to manholes under cities.

      Tunnels don't exit anywhere. If they were close to the water then I may be able to add an exit there, but this isn't the case for any of the cities and most of the secondary buildings.

      Caves are possible but difficult. They would either need to be added with voxels + Marching Cubes, lower and upper height maps that meet at the sides somehow, or possibly a flat floor and heightmap walls and ceiling. I would also need to find a way to keep them from intersecting with other underground objects and the terrain above, using some sort of envelope function.

      Delete
  2. Wow, this underground tunnel system sounds really cool! I love how you’re expanding the complexity of the basements with these new features. The attention to detail, like the metal grates and dark fog to make the tunnels feel endless, really adds to the atmosphere. It makes me think of all those mysterious underground worlds in games that leave you curious to explore every nook and cranny.

    If you’re looking for something equally immersive but a bit more lighthearted to unwind, I highly recommend Hungry Shark. It's an addictive and fun game where you get to explore underwater environments, feeding on fish and growing your shark. It's the perfect balance to all the intense underground exploration!

    ReplyDelete
    Replies
    1. You think so? That first paragraph is pretty well generated if it is. Not like the generic responses I usually get from bots.

      Delete
    2. Profile is full of product links. Website is the Wendy's menu.

      Delete
  3. This comment has been removed by the author.

    ReplyDelete