Language

Randomly generated city - Creating rooms

I am randomly creating a city from a selection of randomly generated building tiles. I want to make it so the player can enter any of these buildings. The way I see it, there are two ways I can do this:

Create the rooms as part of each
buildings mesh and rely on using
occlusion so the scene is only ever
rendering the rooms the player can
see. Each room will also have
randomly generated items, so I'm not
sure if this technique will work?

Generate a room only when the player
enters the buildings door. This
seems like the most efficient
technique as I'll only be rendering
the rooms that the player has
'opened'. The problem here is that
when the user opens a door, the room
behind it needs to load in
seamlessly without a loading screen,
how would I get around that?

1 Reply

You can use proximity and visibility to take a good guess at when to start loading rooms.
You can, for example, put a box collider somewhat larger than your building where the building will be. When a player enters that bound, start loading the interior. He may not go in, so that may be a waste. In that case, you could check the visibility of the collider (or building) to see if the user is looking in that direction. You can also check his velocity to see if he is moving toward the building. BTW the proximity bound need not just be a simple box larger than the building. It can be any shape, or group of shapes. For example, you could put small boxes in streets and alleys that trigger the loading. You see many games where there's sorta an 'airlock' where you enter a small hallway and need to go through a door at the end. This is why. Entering the small hallway loads the content behind the next door.

You can load scenes additively. A scene may have its own occlusion culling in it, so if you do it that way, at least the interiors can be optimized.

I would love to see more LOD (load-on-demand and level-of-detail) support in Unity to support this type of thing. I saw it in Unreal and it's amazing. I've seen it in VRML/X3D too, for a long time. And I know people have coded it themselves in Unity (I heard all of Paris is in Unity this way), but an Asset Store package would be wonderful. Or better (for us) just make it part of Unity 3.5