So here it is. Terrain generation is back, now in Unity. I started learning Unity (from basics, how it works etc.) over week ago. And it’s amazing! It has very good documentation and helpful community. Here we have my terrain generator made in Unity.[youtube http://www.youtube.com/watch?v=hziuLRpN2fg]
Unity made it easy. I could write my own function using, for example Fractional Brownian motion with some noise function, but I was too lazy to do that. I used Mathf.PerlinNoise:
And yes, I know seed doesn’t work that way but this was the easiest way to make terrain generation dependent on seed.
After clicking button chunks are generated. After generating chunk it creates thread which builds triangles for terrain and water. Threads are made with System.Threading. Unfortunately it’s still slow and laggy during generation and building triangles but at least it is made ‘in background’. After building triangles there is made GameObject with MeshFilter, MeshCollider and MeshRenderer. There is no water physics, objects just fall through it, but it’s transparent. There is no blocks, it’s just something like Terrain that comes with Unity.
Drawing height map
To get color of terrain from value 0.0-1.0 I used idea from this site. Basically this is the whole thing:
Here’s my code:
And it looks like this:So that’s all about this terrain generator. I will probably get back to this idea someday adding for example water physics (buoyancy) and more!