# Implementing a lego-like system that doesn't hog computer resources?

I've heard of the term "voxel" used with modern block-builder games such as minecraft. Other games implement what appears to be a voxel system -- yet they incorporate complex 3d objects such as guns, spinning wheels, etc.

In unity3d, how does one implement a builder system that does not compromise performance?

Robocraft is an example of this, though games like Rust and Unturned do feats like this as well.

One obvious thing is to combine meshes to reduce draw calls, but then I wonder how to include individual blocks for consideration in damage, etc.

The term Voxel is very broad. Due to the popularity of Minecraft, many people think a voxel game can only consist of blocks (like Minecraft, Cube World and Seven Days to Die). However, this isn't true.

Voxel worlds usually use a three-dimensional data set to represent the terrain. In cases like Minecraft, the data set contains what block there is at certain places. In some other games, however, it tells you how much material there is at that specific point. The latter version usually uses some sort of iso-surface algorithm (like marching cubes or dual contouring) to display the terrain. Many games like Space Engineers (which is a mix of the two), the recent Astroneer or Mediavel Engineers are in this category.

It's not necessary to use perfect squares if you implement Voxel terrain the "Minecraft way", you can use irregular shapes, slopes or block sized models for it too. It has nothing to do with the complexity of the graphics.

Implementing a game like this can be achieved in multiple ways. One method of optimization is to separate the terrain into chunks, then only render the visible ones and the ones that are close to the player.

• Thank you very much. It does seem as you say that the term voxel is broad as well as it's application. I might have to just create my own implementation. – Pipsqweek Jan 30 '17 at 0:29

One obvious thing is to combine meshes to reduce draw calls, but then I wonder how to include individual blocks for consideration in damage, etc.

The unity-way would be to add sub game-objects with box-colliders to represent all the blocks which are on the surface. Those blocks which are obscured don't need colliders, because they won't ever collide with anything. Also, you can mark the game objects of most of these colliders as static, because even if adding and removing blocks is a main feature of your game, the vast majority of blocks won't move ever. The Unity engine can make lots of optimizations when it is told that an object is stationary.

When this turns out to be too slow, you can try to implement collisions yourself. Instead of having colliders on everything which can collide and having OnCollision* methods, have the Update functions of your objects check for intersections with the voxel grid.

But keep in mind that general-purpose game engines like Unity are not optimized for games with such unusual technical requirements like Minecraft.