In this first lesson of the Unity 3d Fundamentals Series we will start by creating the Terrain for our main scene using the Unity Terrain Engine.
- Create the Terrain;
- Model the Terrain;
- Decorate the Terrain
- Add a Skybox.
Create the Unity Terrain
Just like every other entity in our scene, a Terrain is just a GameObject with a Terrain Component attached. Create a new Unity Terrain by using the Hierarchy View Create Menu.
The first thing I advise you to do is to change the terrain size. By default it is quite large and in this example we just a need a very small terrain for our scene.
Adjust the terrain size to the following values:
- Width: 100
- Length: 100
- Height: 50
Model the Unity Terrain
Now that you have your terrain with the right dimensions, it is time to start modelling.
The Unity Terrain Engine has three tools that allow us to model our terrain:
- Raise/Lower Tool;
- Paint Height Tool;
- Smooth Height Tool.
How to use:
LMB to Raise
LMB + SHIFT to Lower
The opacity value defines the strength of your brush when raising or lowering the terrain.
I usually decrease this value approximately to 30 because higher values make the effect quite exaggerated.
When working with smaller opacity values you may need to paint several times over the same area in order to get start having effects. But I prefer this way because we have a better control over the result.
I also like to apply a small noise effect to all terrain area to get rid of the completely flat areas.
Smooth Height Tool
How to use:
LMB to Smooth
When working with the Raise/Lower tool you will see that eventually your terrain will start to create some pointy areas. Unless this is what you are looking for you can use the smooth tool to correct those areas.
I always work with the smooth tool with the maximum opacity. To apply the smooth to an area of your terrain you need to click and hold and just keep moving the brush on the same area until you reach the desired effect.
I usually also apply the smooth to the noise effect in order to get a non–flat but smoothed terrain.
Paint Height Tool
The paint effect allows you to raise or lower your terrain to a specific height by clamping the terrain at the value defined in the Height property.
You can also change the overall height of the terrain by using the Flatten button. This is quite useful when you want to lower some areas of your terrain to create lakes or rivers for example.
Decorate the Unity Terrain
When you are done modelling your terrain it is time to start decorating it. You have three options when decorating your terrain:
- Paint Texture;
- Place Trees;
- Paint Details.
To start painting your terrain, first you need to add the texture you will be using.
When adding a new texturing we have two slots to assign textures. We will only be using the Texture one. The one for the Normal Map does not work with the default terrain shader and we will not be covering this on this lesson.
When choosing the texture you may want to filter the results by searching for the texture name.
The first texture you add will be applied to all terrain. You can edit the size of the texture by changing the tile property. I usually like to work with tile values around 10-15.
Decreasing the tiling size will make the texture much smaller and to repeat more times.
Increasing the size will make each tile much bigger and to repeat less times.
We need to have several textures in order to get a better looking terrain. So add some more textures to the Paint Texture tool.
How to use:
LMB to Paint
The terrain textures work as layers. When painting with more than one texture we will need to adjust the opacity effect in order to get more or less blending.
The Opacity level controls the strength of our brush when painting the new texture. The higher the value, the quicker the texture reaches the full opacity.
We can control the maximum value of opacity by changing the Target Strength. If equals 1 the new texture will be completely opaque and so no blending effect.
Keep painting and messing with the values until you reach the desired effect.
The Unity Terrain Engine allows to easily place tree models on the terrain. Just like in the Paint Texture Tool, we first need to add the tree models that we are going to use.
Then we need to select the tree from our assets list. On the Add Tree dialog we can adjust the Bend Factor for the tree. This will set how much the tree is able to bend when reacting to the wind.
When choosing a tree model you may want to filter the results by searching for the tree name.
We are going to add some more trees. In this project I have imported the following trees:
- Tree Acacia A;
- Tree Acacia B;
- Small Savanna A;
- Small Savanna B;
Now that we have set our tree library, we have two options to place the trees on the terrain: Mass Place Trees or the manual way.
The Mass Place Trees is an automated process. We just need to define the number of trees that we want to place and it randomly place trees on the terrain using the ones from our tree library.
This method is great to place trees all over your terrain without any hassle.
However you cannot control where the trees are placed or the amount of each tree that is being used. But to be honest I usually like to start with this one and then adjust the trees using the manual process.
How to use:
LMB to place trees;
LMB + SHIFT to erase trees;
LMB + CTRL to erase only the selected tree type;
We have several options to control how to manually place the trees:
- Brush Size: Area to place;
- Tree Density: Adjust the amount of trees to place on the area;
- Color Variation: Randomly changes the tree color to create some diversity;
- Tree Height and Width: Adjust the overall size of tree. 100 is the original tree model size;
- Height and Width Variation: Randomly scale the tree inside the interval (e.g. [Tree Height – Variation; Tree Height + Variation]);
Using the manual process we can add and remove trees until we reach what we are looking for.
I am not using the paint details tool on this project so I will just jump over it. But if you are interested in knowing more about this tool check here.
Add a Skybox
Now that we have our Terrain we need to add a Skybox to make our scene more realistic. First we are going to import the Skyboxes package provided with Unity3d.
After importing all assets inside the package we need to select and apply a Skybox to our scene. First we will open the Project Render Settings.
Then we drag our skybox material into the Skybox Material slot or just press browse.
While choosing the skybox we can filter the results by searching for the material name. In this case we will try with sky.
And we are done. Our terrain is completed and the skybox is in place.
On the next lesson we will create the setup for our First Person Controller Weapon.