Ok so I have this system where when my “game” is started up, a “world” comprised of (2x2x2 meter cubes) is procedurally generated. When finished it looks like 100 cube wide, 10 cube tall, 100 cube long mega-cube, which is the world. The player can then dig into the cubes, which deletes them, and allows them to make “caves” in the cube.
The problem is that generating the 100x10x100 cube world slows the frames per second to like 3.2, and the world generation process even has a delay between every 100 cubes generated, making the world finished in about 2 minutes.
Even after the world is done being built, the game runs at extremely slow FPS, I suppose due to all the cubes being rendered.
Why does this happen? Minecraft (and similar games, like Ace of Spades etc) have MUCH larger world’s consisting of probably 2000x2000x2000 cube worlds, and I don’t walk around lagging from all the cubes when I play those games. Also their worlds take much less time to generate.
How do they get such good performance? There is nothing special about the cubes I’m using, they are cube primitives with a texture material on them so they look like rock.
If I remember, the cubes used in those games are all part of a single mesh. When they’re destroyed, an object isn’t removed. The mesh is altered to remove the piece you mined out. The math behind it is rather complicated, but suffice to say, you won’t be able to achieve the same performance with separate cubes.
Yea that sounds complicated, is the same thing possible in Unity? (By “same thing” I mean even something that mimics it, because in the eyes of the player it is the same)
As a little side-question, is it possible to deform the mesh of a Terrain in Unity during runtime? Like if I wanted to make it so an explosion leaves a “crater” in the Terrain mesh.
Yes, but you have to alter the mesh. Search around the forums.
As GargarethSunman said, the main issue is having too many independent meshes in your scene. There’s a limit to what you can do with a single mesh, so you’ll need to find an optimal “chunk” size, and create multiple meshes that represent chunks of your world.
The mesh documentation is a good starting point:
http://unity3d.com/support/documentation/ScriptReference/Mesh.html
Additionally, a number of like-minded folks have posted a huge amount of material on the subject to this thread:
http://forum.unity3d.com/threads/63149-After-playing-minecraft…
Lastly, you could take a look at Voxelform. If you’re looking to create a blocky world, it may not be your thing, but it does handle an organic Minecraft like world quite well.
I’d recommend trying this demo first, as it’ll run reasonably well on most systems:
http://cyclopsframework.org/voxelform/triplanar/
If you have a core gamer rig, then perhaps give this one a try as well… it’s currently unlisted, but is the best performing high-end demo:
http://cyclopsframework.org/voxelform/test/
Best of luck!