Make a terrain, road and let camera follow the road, with unity 2.6 [Free for non commercial use]. Capture images and make a video with ffmpeg.

Make a terrain, road and let camera follow the road, with unity 2.6 [Free edition]. Capture images and make a video with ffmpeg.

The following tools/scripts are needed:
1. Road/Path Tool. Site:
2. Terrain Toolkit (there is a tutorial video for TerrainToolkit. Watch this if possible). Site
3. SplineController. Site
4. ffmpeg (for making the video from images). Google for ffmpeg binary.

Create A New Project:
* Click on File -> New Project. Type a name for the project, for example “C:\Users\Rabiul\Documents\MyUnityProject”. Check Standard Assets.unityPackage, let the Toon Shading.unityPackage unchecked. Click on Create. This would import standard resources/assets to the new project folder.

* After creating the project this would like something bellow. You can change the look by clicking Window->Layouts and select suitable view, or you can also drag and drop a window to the position you like.

Import the tools/scripts:
* Unzip the file “”. Double click the file – “TerrainToolkit_v1.0.unitypackage”. This will make the unity to import this package. When a dialog comes up, click on Import button. After completion you will find the TerrainToolkit on the Project pane as bellow:

* Unzip “”. Double click on the file “PublicRoadPathTool.unitypackage” and import the package as before.

* Right click on the TerrainToolkit and select Show in Explorer. This will open a window where your project is saved and all the assets were imported. Here we will bring the “SplineController”.

* Unzip “”. Copy and paste the “SplineController” folder here, inside Assets folder. [You could also drag the folder on unity’s Project pane. This was copied via explorer to get an idea about unity’s project management system.]

Create Terrain:
* Click on Terrain->Create Terrain.Scroll mouse wheel down (or up) to zoom the terrain for a suitable view.
* Right click on the gizmo located upper right corner of the “Scene” window, and select Top. As:

And the view changes like:

Draw Road:
Save the “scene”, press CTRL+S and type a filename. Click Terrain on the Hierarchy pane. Make sure the position is 0 for all the X, Y, Z (Inspector). Expand RoadPathTool on the Project pane. Drag PathScript on the bottom of the Inspector pane. As:

* Click on New Path.There will be a new entry ‘Path’ on the Hierarchy. Select it. On Inspector check ‘Road’. As:

* Click on ‘Add path node’ and right click on the terrain (Scene window) where you want a road to start. Press key – ‘P’ on keyboard. Click on ‘Add path node’ again, right click on the terrain and press ‘P’ to make the road extend. Do this as long as needed.

* Click on the ‘Finalize Path’ button after road is complete.

* Expand ‘Materials’ and select RoadMaterial for Element 0. You will see the texture on the bottom of this pane. Later you can drag any other texture to change the color of the road.

* Make the scene brighter by adding light. Click on GameObject->Create Other->Directional Light. Press ‘E’ on keyboard to rotate the light. Drag the light with mouse to adjust brightness. Later you may change the ‘Color’ of the Directional Light on Inspector pane for better result.
Set Camera Way Point:

* Click on GameObject->Create Empty. On the Inspector pane right click on it and rename to ‘waypoint’. Click on the wheel icon on Inspector and select Reset. As:

* Select ‘waypoint’ on Inspector pane and press CTRL+D on your keyboard. This will duplicate the game object ‘waypoint’. Rename the last ‘waypoint’ to ‘a’.
Drag the ‘a’ with mouse and drop it on ‘waypoint’. This makes the ‘a’ as the child of ‘waypoint’.

* On the Project pane expand “SplineController”. Select “Main Camera” on Hierarchy. Drag and drop the script “SplineController” from the Project to the bottom of the Inspector. This attaches the SplineController script to Main Camera.

* On Inspector set waypoint as Spline Parent. Set TANGENT as Orientation Mode.

* Expand ‘waypoint’ and select ‘a’. Press ‘W’ on your keyboard to enable “Move”. On the terrain drag the ‘a’ to the start of the road. Scroll mouse wheel up to zoom in to see the road wide. Click on any white space of the terrain and use Up-Down-Left-Right arrow on the keyboard to adjust view. If necessary select ‘a’ again and try to place it on the middle (of the width) of the road.

* Select ‘a’ and press CTRL+D to duplicate. Rename the last ‘a’ to ‘b’. Drag ‘b’ on the terrain road as the next target for the camera.

* Select ‘b’ and press CTRL+D. Rename last ‘b’ to ‘c’ and drag to make next target for camera.
Make as many target as needed. Name these alphabetically. If sometimes you don’t see any object on the Scene window, select it on Hierarchy pane, scroll mouse wheel once or twice on the Scene window and press ‘F’ on keyboard to get the object focused.

* Do a test now. Click on Play. Probably nothing much can be seen on the Game window. Click on the Play again to make it stop. Select ‘waypoint’ on Hierarchy, on Inspector set the Y value to 2. Click on Play and now the road can be seen. Change the Y value as needed, greater value will set the camera to higher position. You can also change the Y value for the child object a, b, c, d under parent ‘waypoint’, for fine tuning.

** You need to add point/target on the curve more, than it is needed for the straight road. For a large road, zoom out the terrain on the Scene window to make it small. Duplicate and position targets on road with approximate accuracy. Later when completed, zoom in, select each target on Hierarchy and make it focused by pressing F, and position it correctly. To change the speed, select Main Camera on Hierarchy, change Duration value on the Inspector. Higher value will move the camera at lower speed.

Terrain Hill, Tree and Texture:
Read any other terrain howto or search youtube for a better idea. Right click on the gizmo located upper right corner of the “Scene” window, and select Free. Right click again and select Perspective. This view is perhaps easier to make hills and place trees. Select Terrain on the Hierarchy, on the Inspector select Brush and draw on the terrain. You can place trees, grass or work with texture. Test these. Make hills or place trees on the side of the road. You can also make the trees and hills first, then make the road. I made the road first to get it flat for camera view. Experiment more. TerrainToolkit: Select the Terrain on Hierarchy. Click on Component->Terrain->Terrain Toolkit. This will place the toolkit on Inspector pane. There are many options to make the terrain different. Search the youtube for Terrain Toolkit and see it for better understanding. For a quick texture, click on Texture button. Click on ‘Add Texture’ button for 4 times (maximum 6). On the Project pane expand ‘Standard Assets’, then expand ‘Terrain Textures’. Drag 4 different textures to the newly added 4 terrain toolkit texture boxes. Adjust the sliders and click on ‘Apply Procedural Texture’. You can also click ‘Terrain->Create Lightmap->Create’ for brightness. Ending terrain working here.

* Click Assets -> Create –> Material

* Rename New Material to MySkybox.

* Now 6 textures are needed. Expand ‘Standard Assets’, expand ‘Skyboxes’, expand ‘Source Images’ on Project pane. Select each texture on Project pane and

change Wrap mode to Clamp from Repeat on Inspector pane.

* Select MySkybox on Project pane, on Inspector pane click Shader and select RenderFX->Skybox.

* From Project pane Drag a Front texture (under ‘Standard Assets’->’Skyboxes’->’Source Images’ ) to Front on Inspector. Do same drag and drop for the Left, Right, Up, Down and Back.

* Click on Edit -> Render Settings. Click on Skybox Material and select MySkybox. [Fog can be set here].

Save Image to make movie:
* Click on an empty space on Project pane, so that if any folder was selected before now gets unselected. Click on the Menu Assets->Create->JavaScript.
* Rename ‘NewBehaviourScript’ to ‘SaveImage’ on Project.
* Double click SaveImage. and paste the following & save:

import System.IO;
var folder = “ScreenshotFolder\\\\”;
var frameRate = 25;

function Start () {
Time.captureFramerate = frameRate;

function SavePNG(FileName: String){

yield WaitForEndOfFrame();
var width = Screen.width;
var height = Screen.height;
var tex = new Texture2D( width, height, TextureFormat.RGB24, false );
tex.ReadPixels( Rect(0, 0, width, height), 0, 0 );
var bytes = tex.EncodeToPNG();
Destroy( tex );
File.WriteAllBytes(FileName, bytes);

function Update () {
var    name = folder + Time.frameCount  + “.png”;

* On Project right click on SaveImage and select Show in Explorer. When the window opens press Alt+Up arrow on keyboard, to get to it’s parent directory. Create a new folder here and rename to ‘ScreenshotFolder’. Back to unity program.

* Select ‘Main Camera’ on Hierarchy. Drag and drop ‘SaveImage’ from ‘Project’ to bottom on the ‘Inspector’.

* Click on Play button. Now the images will be saved inside ScreenshotFolder.

* You can select ‘Free Aspect’ and resize this tab to adjust output image size.

Make Movie:
* cd to ‘ScreenshotFolder’. Enter command:

ffmpeg -i %d.png -y -r 25 -sameq -vcodec mpeg4 mymovie.avi

* To attach an audio file to the movie:

ffmpeg -i %d.png -y -r 25 -sameq -vcodec mpeg4 -i audio.wav -acodec libmp3lame mymovie.avi

Note: Remove SaveImage script or disable it by unchecking when not needed. Else it will create image and fill the hard disk.

Backup of the needed files and scripts

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s