Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Voxel Terrain for Rise of a Kingdom by Pico Games

Discussion in 'Made With Unity' started by reveriejake, Oct 17, 2012.

  1. reveriejake

    reveriejake

    Joined:
    Jul 8, 2007
    Posts:
    819
    Updated June 22, 2014

    I am currently using my engine in a new game I am developing called Rise of a Kingdom under my alias Pico Games. The details are very limited but there are samples to the engine online if you want to check it out :).

    The updated terrain engine is still in heavy development and there are still major performance improvements to be made such as currently I do not remove faces from chunk edges as in my previous terrain. However this version is Multi-threaded and still loads amazingly fast given the current vertex count of the entire terrain.

    Feel free to try it out and let me know how good or bad the lag is. The web version does NOT save your terrain changes so when the chunks unload they will reload with fresh generation. In the standalone build the data is persistent.

    LINK:
    http://riseofakingdom.com/media/


    SCREENSHOTS:


     
    Last edited: Jun 22, 2014
  2. Cyrus_Zei

    Cyrus_Zei

    Joined:
    Apr 24, 2011
    Posts:
    41
    nice, liked it
     
  3. MrMitch

    MrMitch

    Joined:
    Oct 17, 2012
    Posts:
    10
    Even though i don't really enjoy minecraft that much i did think that this was cool and it would be interesting to see a MC clone fully developed with Unity3D. Do you plan on expanding on the project?
     
  4. reveriejake

    reveriejake

    Joined:
    Jul 8, 2007
    Posts:
    819
    @MrMitch - Personally I say heck yeah. I would absolutely love to expand this into a full MC clone as a personal project! As a separate project with my developer friends we have already discussed what we could use this for and have hatched up a cool concept that would make heavy use of this tech. Since all of us have busy lives however I am not sure how far that idea will go. But again, I plan on spending more personal time working on it as a MC clone.

    Jake
     
  5. Sir-Tiddlesworth

    Sir-Tiddlesworth

    Joined:
    Oct 19, 2011
    Posts:
    908
    Nice.
    What sources would you recommend for learning about voxels and how to implement them?
     
  6. reveriejake

    reveriejake

    Joined:
    Jul 8, 2007
    Posts:
    819
    Inspiration as I said came about through researching procedural terrain. I think it was a post on Voxels by Sauropod Studio that gave me an epiphany moment.

    More important than the concept of Voxels are the things that will be used to make the experience smooth. You cannot simply generate cubes with cube colliders at the voxel positions. There would simply be too many objects in the scene!

    Main Things Used:
    Hash-Tables
    3 Dimensional Arrays
    Enumerations for Asynchronous chunk loading
    Mesh generation
    Triangle Indexing
     
  7. reveriejake

    reveriejake

    Joined:
    Jul 8, 2007
    Posts:
    819
    I will post some images later on of how the mesh looks without the textures attached. Maybe it will spark some inspiration ;)

    On the desktop version I also have it saving out chunks when the chunk is altered into world files just like in minecraft. Except minecraft seems to save EVERY chunk, mine only saves the ones that are altered. As long as nobody places a block in the chunk then the height algorithm along with the same seen value should never change. Meaning faster load times when chunks are loading ;)
     
  8. reveriejake

    reveriejake

    Joined:
    Jul 8, 2007
    Posts:
    819
    OUTDATED CIRCA 'MINECRAFT CLONE POST' SEE LATEST POST FOR MORE RECENT UPDATES!

    Here are a couple screenshots of the mesh that is generated.





    The gray boxes are the chunks and the blue box is what chunk the player is currently inside of.
     
    Last edited: Jun 26, 2014
  9. Vanamerax

    Vanamerax

    Joined:
    Jan 12, 2012
    Posts:
    938
    I like the smoothness of the gameplay and chunk loading! Minecraft sometimes freezes some frames when altering blocks. Do you have block lighting also implemented? I think that is one of the main causes for lag on block updates..
     
  10. reveriejake

    reveriejake

    Joined:
    Jul 8, 2007
    Posts:
    819
    OUTDATED CIRCA 'MINECRAFT CLONE POST' SEE LATEST POST FOR MORE RECENT UPDATES!

    Okay so not sure how well this one will work... This one loads and saves data from a folder on my website. Probably not the best way to do things but I am curious how well it works.

    If 2 people are on then the data will overwrite the other players data as the chunks dont reload when the file changes.

    Give it a try, create something!
    Play Simi-Online Here
     
    Last edited: Jun 26, 2014
  11. kingcharizard

    kingcharizard

    Joined:
    Jun 30, 2011
    Posts:
    1,137
    pretty cool... what are some other features does it have besides the digging and placing of blocks..
     
  12. reveriejake

    reveriejake

    Joined:
    Jul 8, 2007
    Posts:
    819
    OUTDATED CIRCA 'MINECRAFT CLONE POST' SEE LATEST POST FOR MORE RECENT UPDATES!

    Well not many after only 35 hours of R&D ;). But its coming.

    The online thing by the way isn't really the correct way to do things. I just wanted to get a quick and dirty online type experience up. So its very laggy and buggy lol.

    Anyway keep watching the thread. Im sure I will have some new features as days go by. The next few posts will be non-saving versions until I get the proper game server tech implemented.

    The next focus will probably be on block updates so that the dirt grows grass and the lights light up the scene. Also I will be focusing on the actual Fractal generator. The first posts terrain is generated with a heightmap as proof of concept but in the end it will be seed based fractal algorithm.

    After that I am going to be teaming up with a couple of my dev friends to implement some online FPS action into it. The idea is to have the customization of Minecraft and mix that with multi-player FPS games.
     
    Last edited: Jun 26, 2014
  13. reveriejake

    reveriejake

    Joined:
    Jul 8, 2007
    Posts:
    819
    OUTDATED CIRCA 'MINECRAFT CLONE POST' SEE LATEST POST FOR MORE RECENT UPDATES!

    Just noticed now that you guys are playing with it that there seems to be an issue with the seams of the chunks updating when a chunk is loaded.

    Thanks for playing with it!

    Jake
     
    Last edited: Jun 26, 2014
  14. goldbug

    goldbug

    Joined:
    Oct 12, 2011
    Posts:
    766
    Hey jake,

    First of all, awesome job. It is impressive that you achieved that in just 30 hours.

    I also wrote a Minecraft inspired game in Unity called Block Story. It is currently available for purchase for android, iphone, shortly on pc, and I have a free webplayer demo available. A Trailer is also available.

    Anyway, a while back I wrote 5 articles explaining the very basics for how to make a voxel terrain. I think you will find them very helpful.

    Another must have resource for anyone doing a voxel terrain in unity is this thread. There are 2 years worth of knowledge there. All sorts of algorithms are discussed: Ambient occlusion, colored lights, cave generation, multithreading, mesh optimization, collision detection, ray tracing, infinite terrain, water physics, data structures. It is very long, but it is well worth the read for anyone even thinking of doing this.
     
    Last edited: Oct 18, 2012
  15. reveriejake

    reveriejake

    Joined:
    Jul 8, 2007
    Posts:
    819
    Hey thanks. It actually looks like our methods are very similar anyway. I think if you know what your doing the code will ultimately be similar because there really is only 1 way to do Minecraft correctly ;).

    My chunk sizes are 8x8x64 in the demo on my first post and the only thing that is used to represent a block is the blocks type which is also of type byte. Using that information it will generate the proper mesh and so on. The mesh is generated in much the same way as yours is where it checks the blocks neighbors for a transparent block (air, water, glass, etc...) and produces a face depending on that.

    Anyway as I mentioned above, I am NOT really after making a Minecraft clone with my dev team. The final product will be something very differnt! However, for my own personal enjoyment and for the sake of just programming crap I am going to continue cloning Minecraft. I realize there are TONS of clones out there. All you have to do is go on XBL and look through the list ;).

    Thanks again for pointing out those articles, they will be helpful for the ones who was asking me on resources!

    Jake

    EDIT: I was thinking about doing a youtube tutorial on it called "Lets make a Unity voxel engine" ;)


    Articles on MC Voxel Engine by the creator of "Block Story"



    Helpful forum post
     
    Last edited: Oct 18, 2012
  16. XavLar

    XavLar

    Joined:
    Feb 14, 2012
    Posts:
    143
    If you start the youtube series you will gain your #1 Fan right here :D

    Also are you coding it in Javascript,C# or BOO? I've seen people use those three for their games, just wandering
     
  17. reveriejake

    reveriejake

    Joined:
    Jul 8, 2007
    Posts:
    819
    I started Unity with Javascript because the documentation during the time (Unity 1.4) was way better on Javascript than C#, but now I only program in C# ;).
     
  18. Vanamerax

    Vanamerax

    Joined:
    Jan 12, 2012
    Posts:
    938
    The youtube idea is great! Would definatly be following it along when you decide to make it :D
     
  19. reveriejake

    reveriejake

    Joined:
    Jul 8, 2007
    Posts:
    819
    Wow... People are making some rather interesting words in the online version ;)... Anyway, once I get something presentable made I will start making the YouTube videos.

    Jake
     
  20. The United Guy

    The United Guy

    Joined:
    Apr 4, 2013
    Posts:
    1
    Excuse me can u pls Give me a link to download the Placing Blocks Java script pls
    :|
     
  21. reveriejake

    reveriejake

    Joined:
    Jul 8, 2007
    Posts:
    819
    It was written in C#. The code for placing blocks is just a raycast that detects the triangle face of the mesh, then uses a lookup table to determine where that block is at in the world and in the chunk. Adds 1 to the normal direction of the face. And sets the data value of that block to the block you would like it to be.

    Sorry I don't have the original code anymore but hope that helps.
    Jake
     
  22. tomgsx

    tomgsx

    Joined:
    Mar 26, 2013
    Posts:
    18
    Very impressive! As a newbie to Unity and a veteran to Minecraft... You sir, get 2 thumbs up!

    And in just over 30 hours?! How long have you been using Unity and coding?
     
  23. reveriejake

    reveriejake

    Joined:
    Jul 8, 2007
    Posts:
    819
    Well it could have defiantly been better but for 30 hours I guess it was pretty good. I have been using Unity since Unity 1.4 and they were called "Over The Edge Entertainment". I don't exactly remember what year that was but it was probably sometime in 2006. I started with Unity's Javascript(UnityScript) and moved over to C# several years later. I have been coding in C# probably since 2008. At first, I learned C# through 3DBuzz and their XNA101 courses. But the majority of my learning came from a personal project I started. It was an XNA game engine that I made for my educational purposes.

    Here is a link to the XNA engine video I made. It was basic but it was a good learning experience!

    Jake
     
  24. DryTear

    DryTear

    Joined:
    Nov 30, 2012
    Posts:
    312
    You you're not the only one making an MC clone with multiplayer. anyways do you have a way of selecting different blocks, for now im using the textfield, and I am planning to add Teleportation onto the multiplayer side. Can I take a look at the Voxel Terrain Engine script, because my worl generator just makes a flat floor of cubes. Excited :]
     
  25. reveriejake

    reveriejake

    Joined:
    Jul 8, 2007
    Posts:
    819
    Unfortunately I no longer have the code on my computer and I am no longer doing this project. As you have said, I wasn't the only one working on the project! As a matter of fact there is a really good Minecraft clone already done using Unity.

    But I might still be able to guide you in the right direction.

    What do you mean by "Selecting different blocks"?

    In my opinion, the world generation is the most important thing in Minecraft. A good world generator is very difficult to create! Mine uses a simple height-map and I never fully developed my 3D generation algorithm. You would have to do some research into that! NVIDIA has some very good material on world generation techniques that you could probably translate over.
     
  26. Myhijim

    Myhijim

    Joined:
    Jun 15, 2012
    Posts:
    1,148
  27. reveriejake

    reveriejake

    Joined:
    Jul 8, 2007
    Posts:
    819
    Thread hijacking... :) No marching cubes algorithm..

    Im glad to see so much documentation now about how to make voxel engines. I couldn't find 1 single piece of information on how to build a voxel engine.

    Myhijim, I would be interested in seeing how you handle block behaviors and updates. I only got so far as to have grass grow over dirt blocks. But it was only good in 1 chunk at a time. If I tried having the grass grow in a couple other chunks, it would have issues.
     
  28. Myhijim

    Myhijim

    Joined:
    Jun 15, 2012
    Posts:
    1,148

    Haha sorry about the hijack x) Just thought I could add to you list.

    As for grass, I did not do that, but I did do water physics.

    May I ask how big your chunks are?
     
  29. reveriejake

    reveriejake

    Joined:
    Jul 8, 2007
    Posts:
    819
    I dont remember. If you play the first version I posted on this forum I think it was some strange number like 6. That was before I did bit shifting. I think it eventually ended up being 16x16 or 32x32.

    I also had a for loop that generated chunks in a spiral around the player. Looks very cool and you can see it being generated in the example. I used an enumeration function obviously.
     
  30. DryTear

    DryTear

    Joined:
    Nov 30, 2012
    Posts:
    312
    I believe you jake questioned me about the selecting cubes. I use a textfield inside my building script, so if the stringToEdit == "Wood", so then the boolean choseWood will be set true. Then in the update i check if the boolean is true, if it is then we Instantiate a cube based on what we had chosen. Hey Is there a video tutorial instead on the Voxel Terrain, i seen so many videos but no tuts or source code, I know that theres the MinePackage, but i want to writte my own Generator. Im using a floor generator for the multiplayer, and with a 3 textfields of xyz coords so that players could teleport and create their own isles. Like Minecraft, oh and Jake, can you explain about the heightmaps and how to use them for a terrain. And Chunk loading, saving - ty
     
  31. DryTear

    DryTear

    Joined:
    Nov 30, 2012
    Posts:
    312
    oh and for the grass over dirt - try checking in Update() if theres grass beneath dirt, and make the grass into dirt. And if you place a dirt of grass turn the dirt into grass by using raycasts on dirt and grass to check for blocks
     
  32. Moonlight

    Moonlight

    Joined:
    Jun 7, 2010
    Posts:
    41
    Is this still being developed? Or would you be willing to release the source or do tutorial? PLEASE!!
     
  33. reveriejake

    reveriejake

    Joined:
    Jul 8, 2007
    Posts:
    819
    No it is no longer being developed. I am not sure if I will have the time to produce a tutorial and the source code no longer exists but I will see what I can do in the near future.

    @DryTear: I try to restrict the number of monobehaviour objects I create in memory. So checking "Update()" to update grass for a 64x64 patch of land would mean I would have to run through 4096 update calls assuming the ground is flat. That is far to many updates for such a small surface.
     
  34. reveriejake

    reveriejake

    Joined:
    Jul 8, 2007
    Posts:
    819
    Updated June 22, 2014

    I am currently using my engine in a new game I am developing called Rise of a Kingdom under my alias Pico Games. The details are very limited but there are samples to the engine online if you want to check it out :).

    The updated terrain engine is still in heavy development and there are still major performance improvements to be made such as currently I do not remove faces from chunk edges as in my previous terrain. However this version is Multi-threaded and still loads amazingly fast given the current vertex count of the entire terrain.

    Feel free to try it out and let me know how good or bad the lag is. The web version does NOT save your terrain changes so when the chunks unload they will reload with fresh generation. In the standalone build the data is persistent.

    LINK:
    http://riseofakingdom.com/media/


    SCREENSHOTS:


     
  35. reveriejake

    reveriejake

    Joined:
    Jul 8, 2007
    Posts:
    819
    Never mind about the faces on chunk edges. its now fixed :).


     
  36. reveriejake

    reveriejake

    Joined:
    Jul 8, 2007
    Posts:
    819
    I see that some of you have been playing a bit with the webplayer. Any thoughts so far? I know its not much of a 'game' yet but it will get there quickly!

    I will be updating the webplayer again this weekend. I managed to bump the FPS up to around 350-400fps on my desktop. I know its restricted to 60 in the webplayer but this is important because the next major update will be AI and spawning interactive objects into the world.

    Play the latest build here:
    http://riseofakingdom.com/media/

    Jake