Cube Level Generation

Hey everyone!

I’m trying to generate a Dungeon Keeper based map, filled with cubes. I’ve been reading up on the process though, and as I understand it the process of creating a grid map can (for some reason) be very resource intensive. Therefor, I’m trying to be conscious of performance right from the beginning. Would it be significantly better in performance if I allow the first visible row of cubes to be full cubes and the rest of the map be ceiling planes?

My approach (currently just theory) is to have a script that will store an array of tile GameObjects. Each tile object contains a floor plane, a ceiling plane, and a full cube. The visible walls will be full rendered cubes and the rest only render the ceiling tiles. As the player digs through these full cube tiles, the game stops rendering the full cube and renders a floor plane instead.

As I understand it from reading through these forums, the creation of collider boxes is what really eats up computational time. So if I make sure only the visible wall and the floor tiles have collision (so you don’t run into the wall and you can stand on the floor), would that make the initial load time significantly faster?

And finally, I am concerned about the load time involved in loading an entire tile object with three different objects inside, even if two are not actively rendered. Should I do that, or would a more effective option be to store the data on what type of tile I need in a simple array and then load each individual game object as I need it?

I’m probably going to have several questions as the process continues, so I’ll just update this thread as I think of them. I really hope someone answers; as you can tell, I’m intensely new at this.

It would be better not to use separate cubes, but rather construct the dungeon mesh procedurally. There are some MineCraft-clone topics around here with a lot more information about that, including code.

–Eric

Since each tile (whether it be in floor, cube / wall, or ceiling state) is a separate object that contains data on the health of the tile and what state it is in, are you sure procedurally drawn meshes are the way to go here? Again, I’m very new, so my understanding is that procedurally drawn meshes is a method to draw everything manually, not using objects.

Yes, I’m very sure. Having a zillion separate objects is not a very good idea if you want decent performance. You can do it that way for prototyping, but some kind of procedural level mesh generation would be needed in the end, like it is for MineCraft. You can store the state of the tiles in a 3D array.

–Eric

How about this idea, to make this more manageable while keeping performance: Keep the visible walls as GameObject cubes, and then the ceiling as one big mesh?

And I’m having some serious trouble finding a good tutorial on how to create a mesh procedurally. Can anyone help?

Have a look at the procedural examples.

–Eric

A question about passing multi-dimensional arrays in javascript. I have an array that looks like this:

var level = [
[0,0,0,0,0,0,0,0,0,0], 
[0,10,10,0,0,0,0,0,0,0], 
[0,10,10,0,0,0,0,0,0,0],
[0,0,0,0,0,0,0,0,0,0],
[0,0,0,0,0,0,0,0,0,0],
[0,0,0,0,0,0,0,0,0,0],
[0,0,0,0,0,0,0,0,0,0],
[0,0,0,0,0,0,0,0,0,0],
[0,0,0,0,0,0,0,0,0,0],
[0,0,0,0,0,0,0,0,0,0]];

How do I access this from another script?

I tried:

private var level : Array;
level = GameObject.Find("Levels").GetComponent("Level" + levelNum).level;

switch (level[x][z]){
}

But this gives me an error, "“Operator ‘==’ cannot be used with a left hand side of type ‘System.Object’ and a right hand side of type ‘TileType’.”

Actually; just switching from TileType to a normal int fixed this. But why? TileType is a simple Enum, which I thought were ints?

enum TileType { Dirt, Gold, Gem, Water, Lava, Neutral, P1, P2, P3, P4, DungeonHeart }