Well upto the
fifth blog post wow!
I have learned so much already just from teaching you guys/girls
Now this is starting
chapter 2.In this chapter we will be looking at random terrain generation mostly, a fun playful thing.
This is how we dooooo it!Alright, firstly I am going to show you a very basic example of how you
could implement random generation within a chunk.
Open your project and your chunk script and in the
CreateChunk function change the part that contains (line 22):
- Code:
-
chunk[x,y,z] = 1;
To: - Code:
-
chunk[x,y,z] = Mathf.Round(Random.Range(0.0,1.0));
I'm guessing you can figure out what this change does, just by playing the build.
But I'll explain.
Firstly Mathf.Round rounds
down the number to the nearest
integer, we have this so that the block is still determined by "solid" or "air".
Random range then chooses a
float between 0.0 and 1.0
But.....As you can clearly see, this terrain is.....
horrible. It needs to be
smoother and much more interesting than just holes in the ground. This is where
Simplex Noise comes in.
Now this is going to be a very hard chapter for me to write as I really have no idea on
fractal, perlin or simplex noise. Thus I am probably going to make mistakes.
Where do we startWell, there are
two parts i can clearly see involved in creating a randomised terrain.
1. Generating the Values (Through Perlin, Simplex or Fractal Noise)2. Applying the values (Reading and applying them to our chunk)Let's work BackwardsYes lets start with number
2.We are firstly going to convert the Unity Procedual example's terrain from heightmap code to be
voxel friendly.
Here : http://unity3d.com/support/resources/example-projects/procedural-examplesBy the end of this step we should be able to grab any random heightmap and turn it into a
voxelised world.
So what we are aiming to do in this step is to make our chunk be able to accept a
heightmap and generate a cubic world from its co-ordinates. On
only one chunk.
More Coming Later!