Game Development Reference
In-Depth Information
Step 9. Downloand Chapter Seven/Perlin.js from the
Web site. Add the file to your Project inside a new folder
called Plugins .
Step 10. Modify makeTerrain.js to that shown in Listing 7.3 .
Listing 7.3 Using Perlin Noise to Generate Terrain Height
function Start()
var surface : Perlin = new Perlin();
var mesh: Mesh = this.GetComponent(MeshFilter).mesh;
var vertices: Vector3[] = mesh.vertices;
for (var v = 0; v < vertices.Length; v++)
vertices[v].y = surface.Noise(
vertices[v].x * 2 + 0.1365143,
vertices[v].z * 2 + 1.21688) * 10;
mesh.vertices = vertices;
Perlin Noise
Perlin Noise is the same algorithm used in Photoshop for generating the
Render Clouds filter. The image created by Perlin Noise is grayscale, where
black indicates the lowest altitude and white the highest, as shown in
Figure 7.20a .
In fact, you can create a procedurally generated terrain in Unity (shown
in Figure 7.20b ) by (1) adding a terrain, (2) getting the flat terrain texture
with Terrain > Export Heightmap, (3) opening this texture with Photoshop,
(4) applying Photoshop's Render Clouds filter, (5) saving the texture in the
same raw format, and (6) selecting Terrain > Import Heightmap in Unity to
load the heights.
Search Nedrilad ::

Custom Search