#8 Create Mountains with Unity. Build the Labyrinth

By GameDevTraum

Introduction

In this article we are going to see how to create a terrain in Unity using its own tools and we are going to create a labyrinth using the prefabs that were configured in the second article of the project, click here to download the files and to see how to configure the prefabs.

Go to the project’s Main Page

Before we begin, I invite you to watch the following video.



Description of the objective

Create the labyrinth

To create a model of the labyrinth we are going to use the prefabricated ones that we created previously, we will place them in the hierarchy and we will begin to duplicate them and to arrange them in the space, as it is observed in the following figure.

escena en unity 3d, generacion de laberinto utilizando prefabricados
Fig. 1: Setting up the stage using the prefabricated elements shown in video 2.

Create terrain in Unity

To create a terrain in Unity we will use the GameObject “Terrain”, which will allow us to modify its relief and textures in a simple way using different brushes and parameters.

escena en unity 3d en la que se observa como crear un terreno en unity
Fig. 2: Using Unity tools we can sculpt relief in the terrain.

Download Files

First we download the next Zip file, extract the folders and take them to Unity.

115 Downloads
carpetas de texturas que vienen en el archivo de descarga, unity 3d
Fig. 3: Extract the textures from the download file to add them to the project.

mapas de las texturas que vienen en el archivo de descarga, texturas para unity 3d
Fig. 4: Each texture comes with its Albedo, Metallic and Normal maps.


The next thing we do is remove all the elements belonging to the scenario.

escena simple en unity 3d, suelo con textura cesped
Fig. 5: We start by completely cleaning the stage.

Terrain Component – Unity

As mentioned above we will use the Terrain component to create a mountainous relief for the terrain.

This component uses “Height Maps” or height maps to create reliefs, these maps are grayscale textures in which completely black areas are mapped with minimum height and white areas with maximum height (both heights configured in the parameters), the rest of the gray areas will have a height proportional to its color tone.

We can see this in the following image.

mapa de altura o height maps para general relieve en 3d y crear terreno en unity 3d
Fig. 6: The terrain works with Height maps.

In the hierarchy right click > 3D Object > Terrain.

jerarquia en unity 3d, crear terreno en unity
Fig. 7: From the hierarchy we create a GameObject type terrain.

In the stage a white plane appears and in the inspector we can see that it has two components that define it, the component Terrain and a Collider type Terrain.

parametros del componente terreno en el inspector de unity 3d
Fig. 8: The terrain appears in the scenario and we can see its properties in the inspector.


Terrain Component Setup

It is important that we first configure the basic parameters of the terrain, such as the dimension and the difference that will exist between the maximum and minimum height. Then we can modify these parameters but we will probably lose the design we had.

As shown in figure 9, click on the gear icon to go to the configuration. Then enter the parameters.

The only thing I’m going to change is the resolution of the land, which will be 1000 x 1000.

boton configuracion del gameobject terreno, crear terreno en unity 3d
Fig. 9: First configure the basic parameters of the inspector.

parametros del componente terreno en el inspector de unity 3d
Fig. 10: We adjust the resolution of the terrain.

Texture Setup

We can paint the terrain using different sets of textures that will consist of Albedo and Normal maps. First we select all the normal maps we have, in the inspector we choose the type of texture as “Normal map” and apply the changes. We do this for all the normal maps we have.

mapas de las texturas que vienen en el archivo de descarga, texturas para unity 3d
Fig. 11: Select textures such as Normal Map or Normal Map.

seleccionar tipo de textura en unity 3d
Fig. 12: In the inspector we can select the type of texture. Select Normal Map and apply.

Then select the terrain again and click on the brush icon, then on “Edit Textures…”, “Add Textures” (figures 13 and 14).

herramienta pincel en componente terreno unity 3d
Fig. 13: Select the brush tool on the ground component.

agregar texturas al terreno en unity3d
Fig. 14: We must configure at least one painting for the terrain.

In the pop-up window we can select a texture that represents the Albedo in the RGB channels and its Alpha channel is mapped in the softness. Another texture for the surface Normals. We can also configure the size of the mosaic or TileSize using the fields “Size” and “Offset” that are observed in figure 15.

ventana para seleccionar textura albedo y normal para pintar terreno en unity 3d
Fig. 15: In the pop-up window we select an Albedo texture and a normal texture.

Click on Select and choose first the Albedo map and then the normal map.

ventana para seleccionar textura albedo y normal para pintar terreno en unity 3d
Fig. 16: We must make sure to select the appropriate maps.


We’ll do this for all the textures we’ll use to paint the terrain.

Figure 17 shows some values that work for TileSizes.

textura seamless para suelos, cesped con margaritas, cesped con hojas, tierra y roca
Fig. 17: Working mosaic size values.

Once we set up all the textures, we should have them all available for use in the Textures in Inspector window, as shown in figure 18.

unity 3d componente terreno, texturas seleccionadas
Fig. 18: All the textures of the download have been configured.


Making the labyrinth

First to keep things tidy I’m going to create an Empty GameObject that I call “Maze”, inside which will be all the prefabricated ones that I use to make the labyrinth.

jerarquia en unity 3d, empty object, lights, cameras
Fig. 19: We create an empty object that will contain all the pieces of the labyrinth.

Then I drag all the prefabs to the stage and start duplicating them and moving them to form the corridors.

unity 3d diseño de nivel, armado de laberinto utilizando prefabricados
Fig. 20: We start by placing all the prefabricated parts on the stage.

To facilitate the positioning of the pieces we can use the orthographic view. In figure 20 at the top right we have what is called a “Gizmo” that shows the axes X in red and Z in blue. By clicking on these arrows we can change the view of the scene and if we click on the cube in the center we can alternate the view from Perspective to Orthographic.

In figures 20 and 21 we can see how this orthographic view is. The effect it produces is as if all the elements were compressed into one plane, so we do not observe the depth.

unity 3d diseño de nivel, armado de laberinto utilizando prefabricados
Fig. 21: Duplicate the pieces and move them on stage to build the labyrinth.

unity 3d diseño de nivel, armado de laberinto utilizando prefabricados
Fig. 22: Using the orthographic view and bringing the camera closer we make sure that the pieces fit together.

We also put some doors on the stage. In video 4 of the series we created the prefabricated door, here is the article.

unity 3d diseño de nivel, armado de laberinto utilizando prefabricados
Fig. 23: We place several doors in the labyrinth.

We go into game mode and go through the labyrinth to detect problems. In figure 5 you can see one of the badly placed doors.

unity 3d diseño de nivel, armado de laberinto utilizando prefabricados
Fig. 24: We test the scene for problems.

unity 3d puerta mal colocada
Fig. 25: Walking through the labyrinth we found a door that was badly positioned.


unity 3d puerta mal colocada
Fig. 26: We stopped the game mode to correct the problem.

Relief modeling

Then we’re going to start modeling the mountains. Select the GameObject Terrain from the hierarchy and in the inspector click on the first icon of the component (figure 27).

Then we select some pattern in the section “Brushes” that is observed in figure 28.

herramienta elevacion para crear terreno en unity 3d
Fig. 27: Select the Raise/Lower tool in the terrain component.

pinceles para aplicar la modificacion del terreno, crear terreno en unity 3d
Fig. 28: We choose a brush to apply the modification to the terrain.

The next thing we do is paint in the editor and the terrain will gain height.

modelado de terreno en unity 3d usando componente terrain
Fig. 29: We start painting regions of the terrain to produce elevations and create relief.

Another useful tool is the levelling tool (selected in figure 30).

herramienta de nivelacion de terreno para crear terrenos en unity 3d
Fig. 30: Select the ground leveling tool.

altura de la deformacion que se aplica, crear terreno en unity 3d
Fig. 31: We choose the height value at which we want to level the terrain.

This will allow us to establish a certain height and as we pass it over the terrain in the editor, the lower areas will begin to rise and the higher areas will descend, this is illustrated in figures 32 and 33.

crear terreno en unity 3d usando componente terrain
Fig. 32: The regions below the level rise and those above descend.

modelado de terreno en unity 3d usando componente terrain
Fig. 33: We can establish zones that will have a certain height in all its extension.

relieve montañoso observado desde el interior de un laberinto, juego en unity 3d
Fig. 34: We go into game mode to observe the mountainous relief from the perspective of the labyrinth.

relieve montañoso observado desde el interior de un laberinto, juego en unity 3d
Fig. 35: The highest part of the relief is in the opposite direction to the sun of the scene.

After playing with the tools for a while, I ended up with something similar to figure 36.

The most important purpose of the relief is to cover the horizon and somehow provide guidance to the player.

modelado de terreno en unity 3d, laberinto en el centro
Fig. 36: We use the above tools until we are satisfied with the design.


Apply textures to the terrain

In the final phase of this article on how to create a terrain in Unity we will apply the textures configured above.

Select the brush tool in the inspector, a pattern and a texture.

texturizar terreno en unity 3d
Fig. 37: Select the brush tool, choose the pattern and texture to apply.

Then in the editor we go around the terrain and paint.

We can alternate the textures and with this we can avoid that the ground looks monotonous with an only texture.

aplicar texturas a terreno en unity 3d
Fig. 38: To the base texture we apply another texture in different places to break the pattern of repetition.

The mountains will have a base of earth and then we will be applying in different parts a rock texture

texturizar terreno hecho con herramientas de unity 3d
Fig. 39: We give mountains a base with the ground texture.
texturizar terreno hecho con herramientas de unity 3d
Fig. 41: We apply the rock texture in different parts of the relief.

texturizar terreno hecho con herramientas de unity 3d
Fig. 40: Ground texture in the mountains.
texturizar terreno hecho con herramientas de unity 3d
Fig. 42: Rock texture in the mountains.
escena en unity 3d, generacion de laberinto utilizando prefabricados
Fig. 43: Rock texture in the mountains.

From time to time we go into game mode to see how the relief looks from inside the labyrinth.

relieve montañoso observado desde el interior de un laberinto, juego en unity 3d
Fig. 44: We enter the game mode to observe the results.

escena en unity 3d, generacion de laberinto utilizando prefabricados
Fig. 45: Final design of the labyrinth.

relieve montañoso observado desde el interior de un laberinto, juego en unity 3d
Fig. 46: Final design of the mountainous relief seen from the labyrinth.


Conclusion

We’ve seen how easily we can create a piece of land in Unity using the same tools that the engine provides us. We also apply different textures to give it diversity.

The exercise proposed in this article and video is very simple, but with enough time and practice we can build a number of reliefs.

This type of land has the limitation that caverns or caves cannot be built. For that we will have to superimpose another 3D model.

In addition we have created the labyrinth using the prefabricated ones configured in previous entries. Simply by making duplicates and moving in space.

We can make both simple and complex labyrinths and assemble a level selection system if we wish. The possibilities are unlimited.

Let’s bear in mind that this project is only a prototype, in order to achieve a better graphic quality it is necessary to build better 3D models and use a greater diversity of textures and higher quality. It would be nice to add decorative elements such as rubble or trees.