Hey everybody!
It’s been quite a long time since i’ve updated my blog. So here we go!
Well, i know i will ruin your productivity if i mention this but… have you ever heard about minecraft?
If you haven’t, you HAVE to check it out! You can find it at www.minecraft.net.
So what is minecraft? Well basically you start in an “infinite”, randomly generated world, without anything in your pockets. The goal for the first day is to build a shelter before it turns night. Why? Well, you are not alone! There are “things” that want to harm you and will only come at night or at dark places.
The cool thing about this game is the world itself. It is made out of blocks and you can destroy every block you want. You will need it to create tools, weapons or other type of blocks to build your own awesome structures!
Not enough? Well, then play it with friends in multiplayer!
The current version is still alpha and has a lot of bugs but nevertheless it is so much fun already. And i suggest everyone to buy a copy, it’s 50% off during the alpha phase, so it’s around 10€.
There is also a free version but it doesn’t have the so called “Survival Mode”, you can just build anything you want with an infinite amount of blocks.
If you need some ingame footage first, check out this awesome trailer i’ve found: Awesome Minecraft Fanmade Trailer!
Okay anyway, as game designer i wondered “how the firetruck can i do something like this?”.
Now i didn’t have a lot of time, besides playing LOTS of minecraft, i also have to work on many projects. But when i just got sick a few days ago, i couldn’t resist but opening my NEW AWESOME EPIC UNITY 3 PROFESSIONAL VERSION! (sorry, got a little excited here), and recreate something like minecraft (note how i make it sound easy to include EVERY minecraft feature into “a few weeks of lame work”, yeah i am awesome 8D).
So yeah, my first system sucked. My second system got better the worlds were still too tiny. But then the user “Beezir” from the Unity board showed me his voxel system and it was epic, the worlds seem to be “infinite” so i adopted his code (with his permission of course) and changed it to my needs. And viola, my world is huge infinite now!
(This is a shot from my second system, not the newest one:)

If you are a nerd and want to know how it works in details, keep reading. If not, jump to the “Non technical version”.
Technical Version:
Voxels:
So you want to know how it works in detail? Okay sure, let me try to explain it as good as possible!
If you have such a giant world, you will see a lot of cubes (lets call them voxels) at the same time. Normally it wouldn’t be possible to render so many voxels without using some kind of tricks, cause the drawcalls and polygon count would explode your graphics card.
So the first thing to do it, create each voxels manually. That means, a cube has 6 faces, top, bottom, left, right, front, back. We will create each face per script depending on if we would be able to see it or not.
Lets say you have 2×2 voxels, then the faces between those voxels are not necessary to draw, cause we won’t be able to see them anyway. It sounds like it would be slow to check if there are voxels around us and then create faces, instead of just spawning a pre-made cube. But this will actually decrease the drawcalls and polygons by A LOT, you wouldn’t be able to get this kind of result with cubes.
That’s the basic method to display millions of voxels at the same time without destroying the framerate.
Chunks:
So let’s say we had a grid of 512x512x128 voxels. The levelgenerator would have to loop through each block and check if there are blocks around us, that means it has to check it 6 times per block. How many loops would that be? Well that’s easy to find out, 512x512x128x6 = 20.447.232 loops per frame if the terrain changed. Ouch! That can’t work.
Accessing so many voxels would kill the frame rate, depending on how far you can see. That’s why we will group some voxels into a chunk and let that chunk do the job for it’s own voxels. In my code, a chunk contains 16x16x16 voxels, so that’s 4096 voxels in one group. Now the levelgenerate doesn’t have to go through every voxel and check if it needs to get recreated, now every chunk will do the job for it’s own voxels! That means the levelgenerator now only has a size of 32x32x8 (because 512 / 16 = 32, and for the height its only 128 / 16 = 8) and tell that chunk at this position to regenerate it’s voxels. So that makes 8.192 loops per frame if something changed for the levelgenerator, that’s easy for him, perfect!
The chunk itself needs to loop 16x16x16x6 times now so that’s 24.576 times, still pretty easy. Additional what my system does, if a voxel on the border needs to change, it will tell it’s neighbor chunk to update as well so it will hide holes.
With this technic we decreased the number of loops by a lot!
Noise:
/START GERMAN INSIDER JOKE
“Gewitter? In Noise?” – Indeed!
/END GERMAN INSIDER JOKE
This part is just the current level creator. The code from Beezir used a SimplexNoise generator to generate hills and caves and splits it into 4 different layers that could be used for grass, sand, gravel, stone.
To be honest, i don’t know much about Noise algorithm so i can’t say much about it here, i just wanted to mention that it’s a good “placeholder” level generator for the beginning. Later on we will need a better system that can create better looking landscapes.
Accessing Chunks:
To know where a CHANGED voxel is, we use a simple Dictionary. It looks lie this: Dictionary<IntCoords, int[, ,]>();
IntCoords is just a 3 space vector. It stores the chunks position, while the int[,,] stores the voxels position inside that chunk.
Since there can’t be another chunk with the same coordinates, using it’s position as key is quite cool and fast to access.
Okay i think that’s it for the technical version so far. More infos will follow with new dev reports.
Non Technical Version:
So you just want a short summary of how the system works, in a language you can understand?
Well the world is made out of blocks. Displaying so many blocks at the same time would be too much for the computer. That’s why i do severals things:
- Check if we can actually see the cube, if not, don’t show it
- Group 16 x 16 x 16 blocks into a big group and hide all groups that we can’t see
- Generate the world by using a complicated rocket science algorithm
- Only save blocks we changed or added to a big table
Yep i guess you can summarize it like that :)
Future Plans:
I don’t really want to do a minecraft clone, but if i ever going to finish that project, it will include more RPG elements.
You should be able to get EXP from building, crafting, killing, and then level up to get stronger, have bigger inventories, etc.
I was thinking about NPCs who would give you quests or a trader or whatever.
Though i love the crafting system from minecraft, i might using my own system. But i haven’t got any cool idea for it yet.
I also want the graphics to be better, like on the screenshot i’ve posted.
Well that was a long update. I might go through it at a later date to fix some typos and grammar mistakes, but probably not :P
Hope you enjoyed it anyway, and i will try to post a new webplayer version soon!
Greetings,
Captain_Kiyaku
Share on Facebook