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

[Tutorial] Procedural meshes and voxel terrain C#

Discussion in 'Community Learning & Teaching' started by 12pt, Sep 2, 2013.

  1. 12pt

    12pt

    Joined:
    May 22, 2013
    Posts:
    20



    C# Voxel Tutorial

    This tutorial is now out of date, I've replaced it with a new updated tutorial here: http://forum.unity3d.com/threads/tu...h-infinite-terrain-saving-and-loading.293340/

    Learn to create editable voxel terrain made famous by MineCraft and used in a lot of recent games! Voxel terrain has really been taking off recently, it's a great way to create beautiful and interesting terrain and give the player full reign over the environment. It this tutorial we'll be making almost everything you would expect for a prototype voxel game. We'll be using Unity's mesh class to procedurally generate efficient voxel meshes. We start out by making a 2d tilebased platformer terrain to understand generating meshes and storing level data and in parts 5 and 6 we start building chunks of voxels. This is an intermediate tutorial so if you don't have any experience with C# you're going to run into a lot of trouble.

    So how am I qualified to make this tutorial? I've been exploring Unity's options for procedural meshes and voxel systems for about a year now. I've unfortunately moved my focus away from making a voxel game in unity but I feel like it's an area a lot of people have an interest in that should be easier to get into because it's not as complicated as it seems.

    This is an example of my voxel terrain and by the end of this tutorial series I expect everyone
    following along to be able to produce similar results by the end (You can almost do it by the end of part 6).



    Note: Everything covered here is supported by Unity Free, Pro will give you some image effects that might
    make things look better but the things we'll make won't require a pro licence.

    - - - - - - -Part 1: Generating meshes from code - - - - - - - - - - -Part 2: Level Array and Collision Meshes - - - - - -




    - - - - - - - - - - -Part 3: Perlin noise for terrain - - - - - - - - - - - - - -Part 4: Destroying and placing blocks - - - - - - - -




    - - - - - - - - - - - - - - -Part 5: 3d Voxel - - - - - - - - - - - - - - - - - - - - - - - - - - -Part 6: 3d Voxels- - - - - - - - - - - - - - -




    - - - - - - - - - - - - Part 7: Modifying the terrain - - - - - - - - - - - - - - - - - - Part 8: Loading Chunks - - - - - - - - - - - -




    I'm really interested in feedback (This is my first tutorial series) and will do my best to help if anyone has problems. Taryndactyl has already been really helpful in fixing the first few tutorials of problems and I'm trying to get better at avoiding making mistakes but I still need people to let me know if something doesn't work, even if you manage to fix it the next guy might not so leave a comment.

    There are also a lot of great resources out there about voxel development and other concepts that aren't necessarily directed at unity or voxels that are still very helpful, here are a few of those:​
    Let's make a Voxel Engine: Concepts behind a Voxel engine explained in detail by the developer of Vox.
    LibNoise: Using noise functions to do amazing things (Voxel engines use noise for adding randomized detail to terrain)
    Save Mesh Created by Script in Editor PlayMode: How to save a mesh generated from code ingame by UnityCoder.com
    Pathfinding in unity for voxel structures: Again from UnityCoder.com pathfinding for voxel games
    Unity forum's "After Playing MineCraft" thread: You've probably seen this but this is the main thread where people have made MineCraft like games using Unity
    Cubiquity: An excellent free voxel terrain asset for Unity
    More Voxel Resources: Lastly, UnityCoder.com lists even more voxel resources
     
    Last edited: Jan 26, 2015
    Nanior, Gixtox, JohnParask and 2 others like this.
  2. Taryndactyl

    Taryndactyl

    Joined:
    Jan 26, 2013
    Posts:
    16
    I will definitely check these out and if I like them you will surely hear back from me. Wish me luck, I love learning this stuff!

    EDIT: I noticed errors in your code.

    Code (csharp):
    1. newUV.Add(new Vector2 (tUnit * tStone.x, tUnit * tStone.y)
    Should actually be:
    Code (csharp):
    1. newUV.Add(new Vector2 (tUnit * tStone.x, tUnit * tStone.y));
    The final parentheses and semi-colon are missing.

    And then:
    Code (csharp):
    1. newTriangles.Add(0);
    2. newTriangles.Add(1);
    3. newTriangles.Add(2);
    4. newTriangles.Add(0);
    5. newTriangles.Add(2);
    6. newTriangles.Add(3);
    Suddenly becomes:
    Code (csharp):
    1. newTriangles.Add(0);
    2. newTriangles.Add(1);
    3. newTriangles.Add(3);
    4. newTriangles.Add(1);
    5. newTriangles.Add(2);
    6. newTriangles.Add(3);
    Without any explanation.


    Also, you may want to bold the added line
    Code (csharp):
    1. mesh.uv = newUV.ToArray();
    Just to make sure you get the reader's attention with that other wise it looks wrong.


    What I think about this tutorial:
    I only finished the first one but I quite like it already.
    I will be viewing the rest now.
     
    Last edited: Sep 2, 2013
  3. 12pt

    12pt

    Joined:
    May 22, 2013
    Posts:
    20
    Thank you so much for pointing out those errors, this is the first tutorial I've written so I'm bound to make a few errors so it's nice to have people who know their stuff. I'm glad you like it! Procedural mesh generation is very exciting :D
     
  4. Taryndactyl

    Taryndactyl

    Joined:
    Jan 26, 2013
    Posts:
    16
    Tutorial #2

    I am getting 20 compiler errors using your exact code.

    Here they are, and how to solve them.
    1. The name 'z' does not exist in the current context. (GenSquare only uses x, y, and texture)
    2. Vector3s have some invalid arguments. (Vector3 uses floats (not ints), i.e. 1f)
    3. Argument #3 cannot convert 'object' to 'float'. (fixed by adding "float z = transform.position.z;" to the top of GenSquare)

    In GenCollider the Vector3s need to be floats, not ints.

    I noticed the line
    You mention faceCount as if it's a variable, but that is the ONLY time you mention it... is something missing?


    After about 30 of fiddling with my code and redoing this over and over I discovered why my collider meshes were not being rendered.

    $Screen Shot 2013-09-02 at 5.23.28 PM.png
    Be sure to check your Gizmo visibility setting and ensure that Mesh Collider is checked on!

    Now on to Tutorial #3! (These are great by the way, definitely worth the time!)
     
    Last edited: Sep 2, 2013
  5. Taryndactyl

    Taryndactyl

    Joined:
    Jan 26, 2013
    Posts:
    16
    I apologize for the double post but I did not want to make this another edit as it is for another tutorial.

    Tutorial #3

    In the new GenTerrain function you use 'py' in a For within another For that also has a variable 'py'.
    This causes a scoping problem. This will explain scoping.

    Your
    is too large (or maybe I mucked it up somehow) because Unity decided it was all 1 mesh and threw the error of "No more than 65000" vertices in one mesh. I ended up using
    I was unable to reproduce something like


    Due to the fact that your instructions were a bit unclear with the multiple Forloops.
    Here was my final product, you will notice it is lacking the rolling hills and top layer of dirt/grass.
    $Screen Shot 2013-09-02 at 5.58.14 PM.png

    This was definitely an interesting lesson in Perlin Noise and I'm stoked about the final tutorial!

    EDIT:

    Maybe I will do the final one at a different date. I cannot seem to get the Raycasting to hit correctly.
     
    Last edited: Sep 3, 2013
  6. 12pt

    12pt

    Joined:
    May 22, 2013
    Posts:
    20
    Ow wow, thanks again Taryndactyl. I've updated the posts to fix the problems you pointed out and I changed the array size to 96x128. 128x128 is too large when the array is completely full and it's displaying a block for every slot but I only tested once I had the terrain in place so I switched it to less so that now even completely filled it doesn't exceed unity's limits. I also cleared up what I think was the unclearness in my tutorial with the for loops, I only define py once but at one point there was some code that could have been interpreted as a new for loop whereas I meant it as context to some changes to a few lines in it.

    By the way I think your lack of hills might be that with a 100x100 array size the noise for the dirt and rock height are taller than your array. If you were to use 96x128 instead or instead of adding 75 to the dirt and stone variables added 50 you would see them I think.

    Again, thanks so much for taking the time to solve the problems you've encountered and document them. In the future I will have to start trying my own tutorial in a fresh project to eliminate errors. That must be the best way avoid bugs like these :p
     
  7. 12pt

    12pt

    Joined:
    May 22, 2013
    Posts:
    20
    Ok, Sorry to double post but after a long break I've finished parts 5 and 6 of the tutorial, by the end you should be able to make landscapes of voxel terrain! The main post is updated with links :D



    This is what the prototype made in the tutorial looks when finished with placeholder textures.
     
  8. Yoska

    Yoska

    Joined:
    Nov 14, 2012
    Posts:
    188
    Thank you, 12pt. I haven't done all of it yet but so far so good. By the way, that grappling thing looks very neat.
     
  9. nofosu1

    nofosu1

    Joined:
    Jan 13, 2011
    Posts:
    73
    Fantastic Tutorial, and many thanks to Taryndactyl for pointing out the errors. I love the unity community! Weldone 12pt this has been bookmarked
     
  10. 12pt

    12pt

    Joined:
    May 22, 2013
    Posts:
    20
    I just added part 7, I got really pumped and felt like editing the terrain is pretty essential so I made it.

    - - - - - - Part 7: Modifying the terrain - - - - - -


    Also I did some layout changes to the main post.

    Not sure what to work on next, there are a lot of options so if anyone has any suggestions on what to prioritize let me know. I'm thinking maybe lighting or water but I'm not as experienced in those areas as what I've done so far so we'll see. I could also make a player script or spend a little time on terrain generation or add noise to the mesh vertexes or I could show how to make the chunks load around the player instead of everywhere at once. :D We'll see.
     
  11. cod3r

    cod3r

    Joined:
    Sep 19, 2012
    Posts:
    91
    Very cool! Thanks for putting this together.
     
  12. Wieghant

    Wieghant

    Joined:
    Oct 25, 2013
    Posts:
    1
    Hi, what i'm trying to make is a 2.5d minecraft-like game. I just finished the tutorial with perlin noise and was wandering how would i go about making the front(by front i mean 0 coordinate on z-axis) vertices that are exposed to air (on x,y) have some displacement? I tried playing with the vertex coordinates that have nothing above them but since vertices aren't shared between two nearby block i get these big gaps and can't figure out how to make the vertex displacement work. For more clear idea of what i want: http://forum.unity3d.com/attachment.php?attachmentid=23795&d=1313703312. I'm new to game development and Unity so if you have a solution please dumb it down as much as possible please. Oh also i made my code generate textured squares on top and on the right of the cube (used the collision mesh as an example). $displacement.png
     
    Last edited: Oct 25, 2013
  13. 12pt

    12pt

    Joined:
    May 22, 2013
    Posts:
    20
    Hey Wieghant, it's really cool that you're working with the 2d part of the tutorial. I've always though it would make an interesting game environment. So that picture you linked to is similar to something I've done before with 3d voxels. What I did to achieve that effect was move all the vertices of the mesh up or down based on perlin noise every time it was built.

    Now true, the quads don't share verts with other quads so you can't just apply a change to one and have it apply to all the quads sharing a corner but what you can do is move each vertex based on perlin noise that will be the same for every vertex at those positions.

    Here's an example on the 2d terrain that I put together quickly:

    $wavy.png

    I'm going to be using a script covered in part 6, it's a script that someone else has written and you can download it, it's the link in part 6 called Perlin Simplex Noise for C# and XNA so search for that and follow the instructions to implement it (And sorry, you're going to have to rename the previous Noise function to something else or use Mathf.PerlinNoise but I'm just used to using this noise function). In the start of the genCollider and the genSquare function I generate two floats:

    Code (csharp):
    1. float yNoise=Noise.GetNoise((double)x/10,(double)1000,(double)1000);
    2. float yNoise2=Noise.GetNoise((double)(x+1)/10,(double)1000,(double)1000);
    Like this. The first is for the left side of the block, the other is for the right. Then for every vertex that's +1 in x you add yNoise2 to y and the rest that are just x you add yNoise to the y. Here's an example of my genSquare function's verticies part:

    Code (csharp):
    1. newVertices.Add( new Vector3 (x     ,  y+yNoise     , 0 ));
    2. newVertices.Add( new Vector3 (x + 1 ,  y+yNoise2        , 0 ));
    3. newVertices.Add( new Vector3 (x + 1 ,  y+yNoise2-1  , 0 ));
    4. newVertices.Add( new Vector3 (x     ,  y+yNoise-1   , 0 ));
    You add these values to all the verticies and you'll get noise added to the height of each vertex. Make sure you add only yNoise to the left facing quads for the colliders and your new faces and only yNoise2 for the right facing faces.

    Just a side note, with all those faces with the extras you've added you might run into Unity's vertex limit for the mesh in which case you'll have to make the array smaller.

    Good luck!
     
    1Piotrek1 likes this.
  14. 12pt

    12pt

    Joined:
    May 22, 2013
    Posts:
    20
    Sorry for the doublepost but I just finished the eighth and final part of the tutorial!

    Part 8: Loading Chunks


    I hope everyone's had fun with this and gotten some things made. It's been a lot of fun to write and I'll be making another tutorial as soon as I have time and figure out what to write about. Thanks for all the comments and for all the help ironing out the bugs, next time I'm hoping to have a few testers to try the parts before I release them.
     
  15. skoandi

    skoandi

    Joined:
    Jul 9, 2012
    Posts:
    67
    Could you post the finished project? :) Btw nice tutorial!
     
  16. 12pt

    12pt

    Joined:
    May 22, 2013
    Posts:
    20
  17. MrEsquire

    MrEsquire

    Joined:
    Nov 5, 2013
    Posts:
    2,712
    Hi dude,

    Amazing thread, before I start watching, does this support iOS mobile.
    Can these worlds be created for phone and performance is lag free?
     
  18. Epicwolf

    Epicwolf

    Joined:
    Jul 1, 2013
    Posts:
    2
    Hey, 12pt. I must agree that this is an awesome thread! I've tried to learn mesh generation before, but I've never understood it until now.
    So thank you! This has been a great help for my game! :)

    I've copied the full scripts from part 6 but there seems to be problems with the code:

    1. There were some "\"s that were causing errors. (Line 33 in Chunk, and Line 45 in World)
    2. I get "Assets/Resources/scripts/World 2.0/World.cs(60,10): error CS0103: The name `Noise' does not exist in the current context" when I compile.

    Can you please tell me how to fix the second error?
     
  19. 12pt

    12pt

    Joined:
    May 22, 2013
    Posts:
    20
    Hey Epicwolf, glad you worked through the errors with the backslashes, it's an unfortunate problem with quotes and html that I should probably make a note about in the tutorials. As for the Noise function that's a reference to the script I linked to in part 6, it's an implementation of simplex noise for C# that you'll have to paste into a new c# script. Open Part 6 and find "Perlin Simplex Noise for C# and XNA" on the page for the instructions. I didn't include this one along with the full scripts I posted because it's just a matter of copying this from the implementation in a new file.

    MrEsquire, I haven't run this code on iOS but I have tried it out on android. There are optimizations that have to be made, it won't handle the same size as the computer and you could really improve it by removing the colliders and writing some custom collider code based on the level data. It's definitely doable but it will require more optimization and some compromises.
     
  20. Jagwire

    Jagwire

    Joined:
    Dec 5, 2013
    Posts:
    59
    @12pt

    This is a great set of walkthroughs! Is there any interest on your end for an additional tutorial on smoothing things out with Marching Cubes? Marching cubes is something I just can't seem to wrap my head around. Again, great stuff! :)
     
  21. 12pt

    12pt

    Joined:
    May 22, 2013
    Posts:
    20
    Marching cubes is interesting but I don't think I'll be covering it because while using it in games lets you create and destroy terrain you don't have the precision you get with solid shapes like cubes. Also marching cubes is done slightly differently from plain cubes at it's core, it renders each bit of mesh between the data points while the tutorial renders a bit of mesh for each data point. For example in a 2x2x2 array the tutorial code would create 8 cubes but marching cubes would render one configuration in the center.

    What I have been considering however are some additional tutorials and pointers for specific things you can do with voxels like some basic voxel smoothing, maybe infinite terrain, saving data or creating non-solid blocks.
     
  22. Dunkelheit

    Dunkelheit

    Joined:
    Sep 3, 2013
    Posts:
    81
    Alexandros,

    Thanks for posting this incredible material. I definitively will take a look deep inside it. Two years before, I was very interesting to see the applied techniques, now I have the opportunity. Keep it up! :cool:
     
  23. Jagwire

    Jagwire

    Joined:
    Dec 5, 2013
    Posts:
    59
    I'll take it! :)
     
  24. Epicwolf

    Epicwolf

    Joined:
    Jul 1, 2013
    Posts:
    2
    Very sorry about the super late response! :(

    Ah, I see. I must have been reading too fast and skipped the noise stuff.
    I've got everything working now. :)

    And your ideas for future tuts all sound very useful, but might I suggest a discussion on making a lighting system?
    Directional lights are not too flexible, and with the way everything is set up, I am unsure how to make my own.

    Also, I've noticed that I get a sort of sparkling effect on the edges of the blocks, is there any way to fix this?
     
  25. ChristopherYabsley

    ChristopherYabsley

    Joined:
    Jan 16, 2014
    Posts:
    16
    Thanks so much for this! A really nice introduction into both procedural mesh and perlin noise.
     
  26. 12pt

    12pt

    Joined:
    May 22, 2013
    Posts:
    20
    I'm very busy lately so I haven't been able to do any follow up tutorials but lighting is one of the options I may cover once I have the time but I'm not all that experienced with them myself so that could be interesting. As for the sparkling edges it might be the texture atlas, in the texture's import settings make sure it's importing at full size, set the import to advanced type, turn off mip maps and set filtering to point. That will fix any texture bleeding if that's what you meant.
     
  27. Fishypants

    Fishypants

    Joined:
    Jan 25, 2009
    Posts:
    444
    This tutorial series is extremely awesome! Great job! Reading now . . .
     
  28. RulerOfChaos

    RulerOfChaos

    Joined:
    Aug 21, 2013
    Posts:
    4
    this is great, i never thought procedural generation was so reachable with a good tutorial like yours, thank you very much ! keep it up!
     
  29. BlueSin

    BlueSin

    Joined:
    Apr 26, 2013
    Posts:
    137
    Great tutorial, gives us a ton to work with! Thanks!
     
    Last edited: Mar 20, 2014
  30. herold101

    herold101

    Joined:
    Jan 20, 2014
    Posts:
    22
    Hello, I am getting 3 errors with the exact code. I don't really know how to fix it but hope it helps.

    If I messed the code somehow please explain, Thanks!

    My Code:

    Code (csharp):
    1. using UnityEngine;
    2. using System.Collections;
    3. using System.Collections.Generic;
    4.  
    5.  
    6.  
    7. public class PolygonGenerator : MonoBehaviour {
    8.  
    9.     public List<Vector3> newVertices = new List<Vector3>();
    10.     public List<int> newTriangles = new List<int>();
    11.     public List <Vector2> newUV = new List<Vector2>();
    12.  
    13.     private Mesh mesh;
    14.  
    15.     private float tUnit = 0.25f;
    16.     private Vector2 tStone = new Vector2 (0, 0);
    17.     private Vector2 tGrass = new Vector2 (0, 1);
    18.  
    19.     private int squareCount;
    20.  
    21.     public byte[,] blocks;
    22.  
    23.     // Use this for initialization
    24.     void Start () {
    25.    
    26.         mesh = GetComponent<MeshFilter> ().mesh;
    27.  
    28.         float x = transform.position.x;
    29.         float y = transform.position.y;
    30.         float z = transform.position.z;
    31.  
    32.         GenTerrain ();
    33.         BuildMesh ();
    34.         UpdateMesh ();
    35.  
    36.     }
    37.  
    38.     void GenSquare(int x, int y, Vector2 texture){
    39.         newVertices.Add( new Vector3 (x ,y ,0));
    40.         newVertices.Add( new Vector3 (x + 1, y, 0));
    41.         newVertices.Add( new Vector3 (x + 1, y-1, 0));
    42.         newVertices.Add( new Vector3 (x , y-1, 0));
    43.        
    44.         newTriangles.Add(squareCount*4);
    45.         newTriangles.Add((squareCount*4)+1);
    46.         newTriangles.Add((squareCount*4)+3);
    47.         newTriangles.Add((squareCount*4)+1);
    48.         newTriangles.Add((squareCount*4)+2);
    49.         newTriangles.Add((squareCount*4)+3);
    50.        
    51.         newUV.Add (new Vector2 (tUnit * texture.x, tUnit * texture.y + tUnit));
    52.         newUV.Add (new Vector2 (tUnit * texture.x + tUnit, tUnit * texture.y + tUnit));
    53.         newUV.Add (new Vector2 (tUnit * texture.x + tUnit, tUnit * texture.y));
    54.         newUV.Add (new Vector2 (tUnit * texture.x, tUnit * texture.y));
    55.  
    56.         squareCount++;
    57.     }
    58.  
    59.     void UpdateMesh (){
    60.         mesh.Clear ();
    61.         mesh.vertices = newVertices.ToArray();
    62.         mesh.triangles = newTriangles.ToArray();
    63.         mesh.uv = newUV.ToArray ();
    64.         mesh.Optimize ();
    65.         mesh.RecalculateNormals ();
    66.  
    67.         squareCount = 0;
    68.         newVertices.Clear ();
    69.         newTriangles.Clear ();
    70.         newUV.Clear ();
    71.  
    72.     }
    73.  
    74.     void GenTerrain(){
    75.         blocks = new byte[10,10];
    76.  
    77.         for(int px=0,px<blocks.GetLenght(0);px++){
    78.             for(int py=0;py<blocks.GetLength(1);py++){
    79.                 if(py==5){
    80.                     blocks[px,py]=2;
    81.                 }       else if(py<5){
    82.                     blocks[px,py]=1;
    83.                 }
    84.             }
    85.         }
    86.     }
    87.  
    88.     void BuildMesh(){
    89.         for (int px=0; px<blocks.GetLength(0); px++) {
    90.                         for (int py=0; py<blocks.GetLength(1); py++) {
    91.  
    92.                                 if (blocks [px, py] == 1) {
    93.                                         GenSquare (px, py, tStone);
    94.                                 } else if (blocks [px, py] == 2) {
    95.                                         GenSquare (px, py, tGrass);
    96.                                 }
    97.                         }
    98.                 }
    99.  
    100.     }
    101.    
    102.     // Update is called once per frame
    103.     void Update () {
    104.  
    105.    
    106.     }
    107. }
    //SOLVED
     
    Last edited: Mar 13, 2014
  31. jospor

    jospor

    Joined:
    Oct 23, 2013
    Posts:
    10
    Firstly, thanks for the tutorials.

    How would I go about making some voxels have animated textures? For example the lava in Minecraft?
     
  32. Lumos

    Lumos

    Joined:
    Feb 11, 2013
    Posts:
    49
    Greetings. Your tutorial has helped me immensely in grasping Unity's style of procedural mesh generation. Thanks!
    However, it lacks something - lighting. I tried to fiddle with it and implement something like a dynamic light flow system for caves and such, but I failed miserably. Perhaps this could be one of the "future tutorials"? Pretty please with sugar on top? :p
     
  33. WackoMcGoose

    WackoMcGoose

    Joined:
    Nov 25, 2013
    Posts:
    1
    The entire tutorial seems to be gone (blog moved to new site, which isn't set up). Anyone else seeing this? Tried in both Firefox and Chrome, in case it's a browser-specific block/redirect... same result in both.
     
  34. DevMerlin

    DevMerlin

    Joined:
    Dec 21, 2011
    Posts:
    96
    It's gone. I just found this, tried to access the original.. and got a "This no longer exists".
     
  35. baustin27

    baustin27

    Joined:
    Feb 21, 2014
    Posts:
    12
    Yea i started reading it a few days ago and now i can, procrastination got me again.
     
  36. smonty

    smonty

    Joined:
    Mar 25, 2014
    Posts:
    1
    I just started looking into voxel stuff today. Hopefully the tutorials will be back up soon. :)
     
  37. alessandro_88

    alessandro_88

    Joined:
    Aug 19, 2013
    Posts:
    8
    Hi!

    Thank you very much for this tutorial! But the page (studentgamedev.org) is down somehow and I'm not able to open the tutorials. How can I get to those?

    Thanx!

    Alessandro
     
  38. zyedidia

    zyedidia

    Joined:
    Feb 15, 2014
    Posts:
    1
    The tutorials exist and stugamedev.org is also up, but the poster's links are not correct. Here is the link to the page containing the first two tutorials. The next few are on newer pages (bottom left). The website can be found here. Hope this helps!
     
  39. alessandro_88

    alessandro_88

    Joined:
    Aug 19, 2013
    Posts:
    8
    oh great, thank you very very much!! :)
     
  40. Atone

    Atone

    Joined:
    Jun 23, 2014
    Posts:
    1
  41. Fishypants

    Fishypants

    Joined:
    Jan 25, 2009
    Posts:
    444
    Would love to see how to extend the voxel terrain using surface nets or other method to convert the terrain into a smooth voxel terrain.
     
  42. Makosai

    Makosai

    Joined:
    Mar 4, 2014
    Posts:
    46
    Yes, same here. I'm currently working on such a thing. But, if 12pt wouldn't mind doing it, I'd surely like to see their method.

    I've read through the entire tutorial and made some changes so it's more optimized for a large scale world. Something I would also like to see, in addition to smothing the meshes, is the saving of changed data in an efficient manner and the use of the data[,,] in a way that would never run out of memory allocations. This is a problem that I run into when setting the world size to 1000x1000x1000.

    I am trying to do all three of these things currently; saving data, using data in a way that the world size can be infinite, and smoothing this voxel terrain.
     
  43. ZXYNINE

    ZXYNINE

    Joined:
    Aug 24, 2014
    Posts:
    1
    i am geting errors saying that < is not a function can someone please post a working unity project that i can mess around with
     
    J_Troher likes this.
  44. CowardAgent

    CowardAgent

    Joined:
    Nov 17, 2013
    Posts:
    5
    Hello, I saw your text tutorials about the voxel terrain in unity, but it was block style terrain, so I tried to find a tutorial or something that could help with that for few hours, but I could find anyone expect for your voxel tutorial, but I didnt minecraft style terrain (blocks) I wanted a regular procedural terrain (and not blocks style terrain), can you make a tutorial about this? I hope I am not being rude for asking thing like that
    also if you will make this tutorial, will it be infinite terrain?
     
    Last edited: Aug 24, 2014
  45. yxyx136

    yxyx136

    Joined:
    Aug 29, 2014
    Posts:
    3
    Very good tutorial! Thank you! I just can't figure it out how to make transparent textures to create glass or grass.
     
    Last edited: Sep 5, 2014
  46. everystone

    everystone

    Joined:
    Jan 30, 2014
    Posts:
    7
    Great tutorial!
    I am getting some annoying screen tearing with this 2d method, anyone else solved that? I replaced the texture with my own.
     
  47. 5devilz

    5devilz

    Joined:
    Jun 21, 2014
    Posts:
    5
    Hey guys,
    I have a "huge" problem.
    I'm currently at part 3. I wrote every line so i learn and keep in mind what I'm doing.
    Everything worked fine, till perlin noise.
    if i press start in unity it says:
    - Mesh.vertices is too large. A mesh may not have more than 65000 vertices.
    - Failed settign triangles. Some indices are referencing out of bounds vertices
    - Mesh.uv is out of bounds. The supplied array needs to be the same size as the Mesh.vertices array.

    What I don't understand: why?
    It's the exact same code. Even after using copy and past i get the same error.

    if i set the block size lower and change the dirt and stone setting to 50 it works. But everyone else can use the blocks[98, 128] setting?????

    in advance. thanks for the help :)
     
    Last edited: Oct 4, 2014
  48. Armea

    Armea

    Joined:
    Nov 30, 2012
    Posts:
    1
    Hello,

    i am running into a problem during this part.

    When i try to place or remove blocks. i get an error. i have added the modifyterrain script to the world object. Which was not mentioned in the tutorial, but knew it had to be done.

    error:

    NullReferenceException: Object reference not set to an instance of an object
    ModifyTerrain.SetBlockAt (Int32 x, Int32 y, Int32 z, Byte block) (at Assets/Scripts/ModifyTerrain.cs:125)
    ModifyTerrain.SetBlockAt (Vector3 position, Byte block) (at Assets/Scripts/ModifyTerrain.cs:115)
    ModifyTerrain.ReplaceBlockAt (RaycastHit hit, Byte block) (at Assets/Scripts/ModifyTerrain.cs:94)
    ModifyTerrain.ReplaceBlockCursor (Byte block) (at Assets/Scripts/ModifyTerrain.cs:68)
    ModifyTerrain.Update () (at Assets/Scripts/ModifyTerrain.cs:21)

    code chunk from error:

    public void SetBlockAt(int x, int y, int z, byte block) {
    //adds the specified block at these coordinates

    print("Adding: " + x + ", " + y + ", " + z);


    --> world.data[x,y,z]=block;
    UpdateChunkAt(x,y,z);

    }

    the line marked with the arrow should be faulty according to the log.

    and as the above error shows. it happens on multiple locations using the same line.

    hope you can help me with this since im stuck on this for over a week.

    i even tried copy/pasting entire chunks of code to fix the problem, but even that didn't helped.

    i have added ModifyTerrain.cs, Chunk.cs and World.cs.
     

    Attached Files:

    Last edited: Nov 7, 2014
  49. codycook

    codycook

    Joined:
    Dec 4, 2014
    Posts:
    3
    Hello, I am new to programming and i want to create a voxel game like minecraft but polygonal can u please help me out, how to install ur voxel plugin and use it please? I have always dreamt of making a game like this please help me!?
     
  50. 12pt

    12pt

    Joined:
    May 22, 2013
    Posts:
    20
    Hey everyone, I've updated the main post but thought that I would post here as well. I've rewritten this voxel tutorial in a new form including changes to support the things people mentioned most often as features they would like to see included in the tutorial. The new version includes no limits on map size and saving/loading and I've included a download with all the code at the end of each part for debugging. See the thread here: http://forum.unity3d.com/threads/tu...h-infinite-terrain-saving-and-loading.293340/