Skip to content

02 Terrain

Russ Painter edited this page Jan 12, 2019 · 8 revisions

In this step we'll create the world boundaries and a stylized mountainous terrain.

We want a limited play area that is a 1km square. The player will be limited to going 200m high. We will create boundary objects as a guide and then use mountains as a better looking boundary.

Prepare our Land prefab

  1. In your Unity Project Assets create a folder for Terrain. Once we generate some terrain data, we'll move it in here to keep it organized.

  2. In the Heirarchy panel drop down the Create menu and select Create Empty. Name this object Land. It will contain our bounding boxes and our mountainous terrain. Make sure the transform position is all 0's.

  3. Drop this Land item into the Assets - Terrain folder to convert it to a prefab. We can then use the prefab editor to edit the terrain items in isolation. Double-click the Land item in the Project Assets folder (not the Hierarchy) to edit the land in prefab mode.

Add some boundaries

  1. When in the Land prefab editor, select Game Object - 3D Object - Cube and name it BoundaryWall

  2. Drag the BoundaryWall into the Assets - Terrain folder to make this be a sub-prefab.

  3. Double-click the BoudaryWall prefab to set the common properties for all of the walls. Set the Scale X value to 1000. this is because our playfield is 1km long. Set the Position Y (it's center point) to 100 and Scale Y value to 200. This will be a guide to how high the player is allowed to fly (from 0 to 200m above sea level). Leave the Scale Z value as 1.

  4. Double-click on the Land prefab again. This should now contain our resized border wall.

  5. Click on our one BoundaryWall instance. It's position is based at the center of the cuboid, but we want to move it so that the wall extends from 0 to 1000 in the game world rather than -500 to 500. So change it's Transform X to 500

  6. Drag in another BoundaryWall prefab and set it's Transform Position to X=500, Z=1000

  7. Drag in another BoundaryWall and set it's Rotation - Y to 90 and Transform Position - Z to 500

  8. Drag in the final BoundaryWall and set it's Rotation - Y to 90 and Transform Position to X = 1000, Z=500

We should now have something like this:

Walls Prefab

Fill in the terrain

We want to fill the area inside our walls with a terrain now.

  1. While still in the Land prefab editor select Game Object - 3D Object - Terrain which will create a terrain mesh that partially fills in our area. It should look like this:

    Terrain 1

  2. Select the Terrain object an in the Inspector window there are Terrain tools we're going to use.

  3. You can see that the terrain is too small to fill our area. Click the Gear icon in the Terrain editor. Scroll down to the Mesh Resolution (On Terrain) options and change the Terrain Width and Terrain Length values from 500 to 1000.

  4. Clean up: In the Assets folder, a new Terrain data object have been created by our above actions. Drag this into the Assets - Terrain folder just to keep things organized

Move the Camera

  1. Leave the prefab editor, and in the Hierarchy select the Main Camera.

  2. Position this in the center of our world, but 100m high. So the Transform - Position should be X=500, Y=100, Z=500. This is the highest point that our player ship can go, so we want to make sure things look good from this perspective.

Draw some border mountains

  1. With the first Terrain object selected, in the Inspector window's Terrain editor change the paintbrush tool dropdown to Raise or Lower Terrain.

  2. Select the first brush image that looks like a blurry small white circle. Slide the Brush Size up to about 250 and set the Opacity to 50.

  3. use the paintbrush tool with the left mouse button just along the walls to bring up the land up so that the walls are no longer visible. We are using these walls as a guide to get our mountains to the correct height.

    Mountains

  4. You'll have to rotate the scene view around to make sure all of the walls have been obscured by mountains.

  5. It should now look like a very poorly made pie crust. mmmm... pie...

    Mountains

Draw some hills

  1. To make the playfield area more interesting, use the same raise/lower tools to create some hills in the level. You should probably keep these within our 100m high limit. Try experimenting with different brush shapes and sizes. I don't want sharp edges in mine, so I'll stick with the soft brush.

    Mountains

And your Game Window should now look something like this:

Mountains

Create a Grid Texture

We're going to use our 2D painting software to create a black and white grid texture to apply to the terrain to give it a good 1980s computer vibe.

  1. Open up the GIMP image editing program.

  2. Select File - New and set the image width and height both to 256 and the units drop down to px. It's important when making games to size your images in pixels in powers of two. This means that images should always have one of the following sizes: 1, 2, 4, 8, 16, 32, 64 128, 256, 512, 1024, 2048, 4096. These sizes make things easier on the graphics hardware.

  3. Choose the bucket fill tool and choose black as the color. Dump this blackness all over your image.

  4. We're going to make a white vertical and horizontal line on the image. The locations of these don't matter. Just that they are perfectly straight. Change your tool to the pencil, and select white as the color. Click anywhere above the image just to pick a location. then while holding down SHIFT and CTRL click below the image. This should draw a perfectly straight white line over the image.

  5. Do the same as above, but clicking to the left of the image, then SHIFT-CTRL-CLICK to the right of the image to generate a horizontal line.

  6. In the File menu select Export As and type TerrainGrid.png as the file name. Select where you're projects Assets - Terrain folder is and press the Export button.

Apply the texture to our terrain

  1. Back in Unity select your Terrain object in the Hierarcy. In the Inspector under the Terrain Paintbrush tool select Paint Texture

  2. Just below that, click the Edit Terrain Layers button and select Create Layer and choose your new TerrainGrid.png image. This will create a new asset in the project called "NewLayer". Rename this to "TerrainGridLayer".

  3. With this layer asset selected change the Tiling Settings - Size X, and Y values both to 10. This means that our texture is meant to cover a 10m square area on the terrain.

  4. Play with the Smoothness value to get an effect you like. Lower values are dull like paper, and higher values are shiny like plastic. I'm leaving mine in the middle. and it now looks like this:

    Mountains

Clone this wiki locally