By: Elyse                Categories: 3D AnimationAnimationGames

Let’s get started with the terrain project. This project will begin from an empty Unity project, featuring one empty scene. The first step in creating terrain for a scene is to generate the Terrain mesh – the mesh asset (vertices, edges and polygons) that will act as the terrain. This Terrain mesh will begin its life as a highly tessellated plane – that is, a flat surface whose topology consists of densely packed and regularly spaced vertices. It’ll be our job as the project progresses to use the Terrain tools to sculpt and mould that initial terrain into its final shape, just as a sculptor shapes a composition from an initially formless lump of clay. Consider the following steps.

1. Select Terrain > Create Terrain from the application main menu. (SToP PReSS. In Unity 4.2 or above, Terrains are created by selecting Game Object > Create Other > Terraine.) Clicking this will generate a new Terrain mesh in the scene. In practice, two things happen here ‘under the hood’: first, a terrain Asset is generated in the Project panel; and second, a terrain Mesh is added to the scene as a game object on the basis of the asset. The newly created game object will have both a Terrain component and a Terrain collider component. The former will allow us to sculpt and texture the terrain and the latter to detect collisions with the terrain so that the player character and enemies will walk on top of the terrain as opposed to falling through and descending into oblivion.

NOTE: Almost all of the options considered so far in this chapter will be related to the Terrain group on the application menu.

2. The terrain is generated in the scene as a plane and its default size is 2000×2000 world units, which equates to a gargantuan surface area of 4,000,000 m2! To reduce the size of the terrain, select Terrain > Set Resolution from the application menu. This important dialog allows us to set and edit a selection of fundamental properties for the terrain, not only its size. Almost all of these properties should be set before the terrain is sculpted and textured, because they ultimately influence the underlying structure and constitution of the Terrain mesh. Reduce the terrain Width and Length to 500 world units, and leave the terrain Height at 600 units. Note that editing the Terrain Height setting has no immediate and appreciable effect on the mesh in the viewport. Rather, this setting specifies a potential height or a maximum height: the tallest peak or height at which any mountain or outcrop of the terrain could reach when sculpted, if we so chose. See Figure 4.1.

3. The Height Map Resolution setting of the Resolution dialog specifies the pixel dimensions of a special internal, square texture, known as the Height Map. This texture has a direct and managerial connection to the Terrain mesh. Specifically, the greyscale values of texels (texture pixels) of the ‘Height Map’ map onto and control the elevation of vertices in the Terrain mesh. Black pixels refer to depressions or sunken areas in the terrain (such as canyons), white pixels to extrusions or elevations (such as mountains), and shades in between to intermediate levels of elevation. The sculpting tools act as brushes and allow us to push and pull the terrain into shape. They actually work ‘under the hood’ by painting colour values directly onto the height map to indirectly deform or shape the Terrain mesh accordingly. The Detail Resolution and Control Texture Resolution settings work in a similar way but relate to other aspects of the terrain, as we’ll see later. Leave all these settings at their defaults for this project: in short, the higher the values, the more detail and control you have over the Terrain mesh. This control and detail comes at a performance cost, however. Consequently, these values should be set as low as possible for your needs.

Figure 4.1 Configuring terrain properties through the Set Resolution dialog

NOTE: The height map method of generating terrain means a tessellated, three-dimensional plane is deformed or displaced on the basis of pixel values in a two-dimensional texture file. This method hints at a possible limitation for terrain: you cannot use the Terrain tools to create alcoves, caves, holes, tunnels or crevice-like regions in which an interior space is carved out inside the terrain. This is because a two-dimensional texture lacks the necessary dimensions of information to store this detail. The height map only encodes levels of elevation for the terrain surface. Thus, insofar as the Unity Terrain tools offer sculpting features, they can only be used to raise and lower regions of a plane mesh.


Excerpt from Unity 4 Fundamentals by Alan Thorn © 2013 Taylor and Francis Group. All Rights Reserved.

About the Book

The Unity engine is the tool of choice for many indie and AAA game developers. Unity 4 Fundamentals gives readers a head start on the road to game development by offering beginners a comprehensive, step by step introduction to the latest Unity 4 engine. The author takes a theory-to-practice approach to demonstrate what Unity 4 has to offer which includes:

No Comments

No Comments

Tell us what you think!