Unity - Building Roads

OK, we've built a nice car in previous lessons. Now we need something to drive it on. In this lesson, then, we'll build some roads.


There are a few road systems on the Unity Asset Store. The one we like is Easy Roads by AndaSoft. The paid-for version lets you add things like intersections, barriers, traffic lights, and loads more. But the free version works well, too. You'll only be able to add a basic road, but you can construct a decent racetrack easily enough.

So, head to this page on the Asset Store:

Easy Roads

Download and install EasyRoads3D Free. In the Project area of Unity, you should see a few new folders appear (there's a couple of folders you want have, Nature and Town Pack):

Unity project folder showing Easy Roads installed

There are folders called EayRoads3D and EayRoads3D scenes. You may also have a folder called _TerrainAutoUpgrade.

You can only add these roads on a terrain, however, so we'll have to create a terrain first. We did terrains in another tutorial so won't go into too much detail here.

But add a Terrain to your scene by going to Game Object > 3D Object > Terrain. Notice, while you're on this menu, that there is a new item for Easy Roads:

A menu showing how to add a New Road Network to a Unity terrain

But back to the terrain you just added. It will be sitting on top of your Plane. So, you can either delete the Plane altogether, or just hide it by unchecking the box at the top in the Inspector when the Plane is selected in the Hierarchy.

The default terrain is a bit big. For testing this roads system out, it's recommended that your start with a small terrain, as adjusting your road parts can be a bit fiddly. To change the size of your terrain, click the settings icon in the Inspector:

Scroll down and set the Terrain Width and Height to something like 300. Using the techniques you learned in the terrain section of this course, create a simple terrain.

If you want a completely flat terrain, select Set Height from the dropdown in the Inspector. Then click the Flatten All button:

A flat terrain will make it easier to add the roads.

But your terrain might look something like this, once you've clicked Paint Texture and added a grass to it:

A flat terrain in Unity

Now to add a road.


Adding Roads to a Unity Terrain

From the menus at the top of Unity, click on Game Object > 3D Object > EasyRoads3D > New Road Network.

If you get a dialog box about road type presets being available, just click YES. You'll then see a Road Network item appear in the Hierarchy. In the Inspector on the right, you should see this:

Select the second of those icons, Add New Road. In the Type dropdown box, the free version only gives you one option - Default Road. Select that and your Inspector should look like this:

When you select a road type, the Add New Object button will appear. Click the button. The Inspector will change to this:

Move your mouse over to your scene. Hold down the SHIFT key on your keyboard and left click to add a marker:

Adding a marker for the road

(The markers are blue spheres and indicate where a road segment starts and ends.)

Shift-click again to add your first road segment:

A road segment added to a terrain

Keep SHIFT-clicking and draw a track. But stop when you are almost done, with only one segment left to add:

In the Inspector on the right, check the box for Closed Track: (You can also set the road width here.)

When you close the track, you should have a road that looks something like this:

A road system with a closed track

If you want to edit a road segment, make sure Road Network is selected in the Hierarchy. Now click on the road segment you want to adjust. It should turn red. Just above the Hierarchy, click the position arrows, instead of the hand. This will give you the arrows back in your scene:

Adjusting a road segment

Zoom in and adjust your track segment using the arrows. If you have a flat track, you only need to move the red and blue arrows. Click one of the blue markers to select a new track segment.

To finalise your track, click the Mountain icon in the Inspector, then click the Build Terrain button:

When you click the Build button, you may see a nag about the free version:

It's saying you can't switch back to edit mode in the free version, so make sure your track is the way you want it. If it's all good, click YES on the dialog box.

Once you have your road, position your car on it. You can add some buildings via the Asset Store. There's a low poly building pack here on the store:

Simple Poly Town Pack

Download and install the pack and start adding buildings. You can then get a feel for what your road and final scene are going to look like before replacing the low poly buildings with something else. Here's our screenshot from our game:

A scene with a car on the newly-built road in Unity

And here's a video of us driving around:


OK, this was only a simple scene on a flat terrain using the free version of Easy Roads. But if you were to take your time, paid $40 for the Pro version, you could produce some great roads on your fancy terrains.

In the next lesson, you'll set up multiple cameras and learn how to switch between them.

<--Back to the Unity 3D Course Contents Page