'How to create "Scroll_Track"' (Ver.3.0)

Please feel free to contact me if you have any questions.
shopmaster@chobi-glass.com
http://chobi-glass.com/Unity/index.html



*** Outline ***

This section shows how to create "Scroll_Track" for the tank made in the previous steps.

(Note.)
This project has three track systems "Physics_Track", "Static_Track" and "Scroll_Track".

"Scroll_Track" is a simple belt-shaped track used instead of "Static_Track" in order to improve the performance in the game scenes.


Also the tank is able to have both "Static_Track" and "Scroll_Track" by using "Track_LOD" function that switches the tracks according to the distance from the camera.
About the "Track_LOD" function, we will learn how to use it in the next section.

In this tutorial, we will create the mesh for "Scroll_Track" using "Create_ScrollTrack" object without using a modeling tool.
The shape of the mesh is depending on the arrangement of the wheels in the tank, so we need a tank with adjusted wheels as the base.

In this tutorial, we will use the new tank made in the previous steps.



*** How to create Scroll_Track ***

(0) Make the "Static_Track" invisible.

At first, make the "Static Track" invisible when the tank has it, so that it is easier to work.
Inactivate the "Static Track" by unchecking the box in the upper-left corner of the Inspector window.



(1) Attach "Create_ScrollTrack".

You can find the prefab "Create_ScrollTrack" in the "Tank_Components" folder under the "Prefabs" folder.


Drag and drop it into the "MainBody" in the Hierarchy window, and make sure that the "Create_ScrollTrack" is placed under the "MainBody" as a child.



(2) Create the basic mesh.

Select the "Create_ScrollTrack", and press the "Get Default Settings" button.


The new basic mesh is created according to the arrangement of the wheels in the tank.



(3) Set the basic values.

Set the basic values such as the width and the height (thickness) as you will.
In this tutorial, set as follows.



(4) Adjust the shape.

The basic mesh does not have the ideal shape yet, so we need to adjust the shape by changing the values for each wheel.
In this tutorial, set as follows.



(5) Adjust the UV mapping.

At first, set the "Material" fitting for the new "Scroll_Track", and enable "Show Texture" option in order to adjust the UV mapping while looking at the texture image.
In this tutorial, set as follows.


(Note.)
The texture image is scrolled horizontally along U axis in this project.



Next, set the UV mapping by adjusting the "Line #" values while looking at the texture image.
The yellow lines on the image correspond to each edge of the track mesh.


Also adjust the "Scale" value so that the texture is reflected at the correct scale on the mesh.
In this tutorial, set as follows.



(6) Set up the deforming script.

You can find the "Track_Deform_CS (Script)" under the "Create_ScrollTrack_CS (Script)" in the Inspector window.
Press the "Find RoadWheels [ Left ]" button to set the references used for deforming the track mesh.


The references to the RoadWheels on the same side are set automatically as the "Anchor Wheels".


The vertices (displayed as red dots) within the green square are moved up and down according to each "Anchor Wheel".   
Adjust the range by changing the "Width", "Height" and "Offset" values when the required vertices are out of the range.
(In this tutorial, we need not change any value.)


(Note.)
Press the "Update Value" button each time you have changed the shape of the tracks, in order to store the vertices information.




(7) Set up the scrolling script.

You can find the "Track_Scroll_CS (Script)" under the "Track_Deform_CS (Script)" in the Inspector window.
Press the "Find RoadWheel [ Left ]" button to set the reference used for scrolling the texture.


The reference to one of the RoadWheels on the same side is set automatically as the "Reference Wheel".



(8) Find the appropriate "Scroll Rate" value.

The speed rate for scrolling the texture cannot be set automatically, so we need to find the proper value in the runtime.
The "Scroll Rate" can be changed temporarily in the runtime from the Inspector window.

Find the appropriate value that the texture scrolls synchronizing with the wheels, whie moving the tank forward and backward.
And set the value again in the edit mode.
(Note.)
The value changed in the runtime will return to the original value in the edit mode.

In this tutorial, set the value to "0.0015".


(9) Test the motion in the runtime.

The left one has been completed now.
The right one can be created easily by duplicating the left one, so test the left one in the runtime before duplicating.
Check the following points.



(10) Create the right one.

At first, rename the "Create_ScrollTrack" to "Create_ScrollTrack_L".
Next, duplicate it and rename the new one to "Create_Scroll_Track_R".


Select the new "Create_Scroll_Track_R", and update the values as follows.
  1. Uncheck the "Left" option in the "Create_Scroll_Track_CS (Script).
  2. Press the "Find RoadWheels [ Right ]" button in the "Track_Deform_CS".
  3. Press the "Find RoadWheel [ Right ]" button in the "Track_Scroll_CS".


(11) Test the motion in the runtime.

Make sure that both of the tracks work normally in the runtime.



(11) Save the meshes.

The meshes of the tracks are just temporary data now, so we need to save the meshes in order to use them in other scenes.
Press the "Save new Mesh" button in each "Create_Scroll_Track_CS (Script)".


The new meshes are saved in the "User" folder.



Progress to the next section.

Our new "Scroll_Tracks" have been completed.


"Scroll_Tracks" can be used in combination with "Static_Track" in one tank by using "Track_LOD" function.
In the next section, we will set up the "Track_LOD" function to use the both tracks in our tank.

Please progress to the next section 'How to use "Track_LOD" function'.