b3agz / Code-A-Game-Like-Minecraft-In-Unity

Project files for a Youtube tutorial series on coding a game like Minecraft in Unity.
298 stars 237 forks source link

Invisible chunks #2

Open aaron-jencks opened 5 years ago

aaron-jencks commented 5 years ago

Love your tutorial, but I'm struggling to get my voxels to appear, I'm on part 4 right now, my textures seemed to work okay for part 3, but now nothing shows up, I cloned the repository, and it appears this is a bug with the source scripts and I don't know how to fix it. If all of the blocks are the same type it runs fine, but when I fill the materials list with the 12 blocks on the texture sheet, everything disappears, but no errors are thrown.

I have the textures set up as follows

Size: 12 Everything is solid Stone: 0,0,0,0,0,0 Dirt: 1,1,1,1,1,1 Grass: 2,2,7,1,2,2 Coal: 3,3,3,3,3,3 Planks: 4,4,4,4,4,4 Log: 5,5,6,6,5,5 Cobble: 8,8,8,8,8,8 Bedrock: 9,9,9,9,9,9 Sand: 10,10,10,10,10,10 Brick: 11,11,11,11,11,11 Furnace: 13,12,15,15,13,13 Lit Furnace: 13,14,15,15,13,13

I'm using the source scripts straight from part 4, I went back and swapped my code out for the original and the problem persists.

This is what it looks like when I hit play: image

TheDustySheep commented 5 years ago

I was having the same problem, found that it was a problem with the air block, you might need to set its renderfaces to true.

StarStorms21 commented 4 years ago

Got the same problem! i dont really understand what you mean with the 'air' block...would you mind explaining how you fixed this?...if you did that is

I was having the same problem, found that it was a problem with the air block, you might need to set its renderfaces to true.

benrusza commented 4 years ago

you need a air block in id 0 marked as transparent and not solid, i mean the array of blocks need a value of air in this case was to be 0

Mycos-ToS commented 4 years ago

Air blocks don't exist as of episode 4 but yours works just fine. Just like iggy12345 up at the top, I cloned the files but the chunks are still invisible. I went through every single line of code but it still is buggy. Any ideas?

Also, I tried putting an air block in slot 0 with solidity off and it still didn't work.

BuzzyRobo commented 3 years ago

If anyone is still having this problem, you need to change this bit of code to fix it: ` void PopulateVoxelMap() {

    for (int y = 0; y < VoxelData.ChunkHeight; y++)
    {
        for (int x = 0; x < VoxelData.ChunkWidth; x++)
        {
            for (int z = 0; z < VoxelData.ChunkWidth; z++)
            {

                if (y < 1)
                    voxelMap[x, y, z] = 0;
                else if (y == VoxelData.ChunkHeight - 1)
                    voxelMap[x, y, z] = 3;   <---------Change this to 2
                else
                    voxelMap[x, y, z] = 1;

            }
        }
    }

}`
fefedelcid commented 1 year ago

If anyone is still having this problem, you need to change this bit of code to fix it:

...
voxelMap[x, y, z] = 3;   <---------Change this to 2
...

I have the same problem even using this solution. The only way I can find to show the Chunks is by changing the following line:

bool CheckVoxel(Vector3 pos) {
    ...
    if (!IsVoxelInChunk(x, y, z))
        // return world.blocktypes[world.GetVoxel(pos + position)].isSolid;
        return false;
    ...
}

But this causes the inner triangles to still be rendered... image