Welcome, Guest. Please login or register.

Login with username, password and session length

 
Advanced search

1411469 Posts in 69368 Topics- by 58422 Members - Latest Member: daffodil_dev

April 23, 2024, 02:32:28 AM

Need hosting? Check out Digital Ocean
(more details in this thread)
TIGSource ForumsCommunityTownhallForum IssuesArchived subforums (read only)TutorialsUnity Voxel tutorial series
Pages: [1]
Print
Author Topic: Unity Voxel tutorial series  (Read 4799 times)
AlexStv
Level 0
**


Based on real events!


View Profile WWW
« on: January 30, 2015, 10:44:56 AM »

Voxels seem to be a big, growing trend in games lately and I think it's a great thing. We're going to see a lot of interesting innovation come from so many people experimenting with destructible terrain where you can build whatever you want. It loads of fun for the player and it's loads of fun for the developer. So I wrote a tutorial for making voxel terrain in Unity. I actually wrote one before this which was quite popular so recently I decided to take all the improvements and suggestions and write a this new tutorial incorporating them from the start and building a more extendible core system.

This tutorial uses a chunk based approach to creating voxel worlds with (practically)infinite size and explores saving and loading of save files. With the 6 parts that are released so far you can create all the chunks you want with generated terrain and some default block types (and add more of your own) and save and load those chunks whenever you like. I'm already working on the next part and want to keep this tutorial alive with more and more interesting segments.

Check it out here: http://alexstv.com/index.php/category/voxels

An example of the project after part 6 with some interesting terrain generation

As a side note I've been experimenting with voxel terrain in unity for a while but I am by no means an expert so please let me know your suggestions, improvements or ideas and I'll consider them and make changes and additions where appropriate.
Logged

Layl
Level 3
***

professional jerkface


View Profile WWW
« Reply #1 on: February 05, 2015, 10:17:09 AM »

A bit of a remark on the following bit of code:
Code:
     protected virtual MeshData FaceDataUp
         (Chunk chunk, int x, int y, int z, MeshData meshData)
     {
         meshData.vertices.Add(new Vector3(x - 0.5f, y + 0.5f, z + 0.5f));
         meshData.vertices.Add(new Vector3(x + 0.5f, y + 0.5f, z + 0.5f));
         meshData.vertices.Add(new Vector3(x + 0.5f, y + 0.5f, z - 0.5f));
         meshData.vertices.Add(new Vector3(x - 0.5f, y + 0.5f, z - 0.5f));
 
         meshData.AddQuadTriangles();
 
         return meshData;
     }

Because MeshData and the lists in it are reference type, it makes no difference if you return it again or not, you're not no point creating a copy of the variable but always overwriting it. As a result when you do this:

Code:
var data = new MeshData();
var data2 = FaceDataUp(chunk, 1, 1, 1, data);

"data" and "data2" will point to the exact same object. This may cause some confusion. Another example to make entirely clear what's happening, here's a snippet of code to be run in a C# console project:

Code:
using System;

namespace ReferenceExample
{
class MyObject
{
public int MyValue { get; set; }
}

class Program
{
static MyObject ChangeValue(MyObject obj)
{
obj.MyValue = 2;
return obj;
}

static void Main(string[] args)
{
var obj1 = new MyObject();
obj1.MyValue = 5;

Console.WriteLine("obj1.MyValue: " + obj1.MyValue);

Console.WriteLine("Running ChangeValue()...");
var obj2 = ChangeValue(obj1);

Console.WriteLine("obj1.MyValue: " + obj1.MyValue);
Console.WriteLine("obj2.MyValue: " + obj2.MyValue);
Console.ReadKey();
}
}
}

This will output:

Code:
obj1.MyValue: 5
Running ChangeValue()...
obj1.MyValue: 2
obj2.MyValue: 2
Logged
BudaDude
Level 0
*


If its not broke, you did something wrong.


View Profile
« Reply #2 on: February 06, 2015, 09:26:01 PM »

This looks really good. How is your performance with it? I was always under the impression that Unity starts messing up when there are a lot of gameobjects.
Logged

Siesatia
Level 0
*


View Profile
« Reply #3 on: February 28, 2015, 11:39:17 PM »

I'm getting 0.2 FPS as of Update 7, will we be seeing further updates to this? Perhaps some work on performance?
Logged
Pages: [1]
Print
Jump to:  

Theme orange-lt created by panic