People Innovation Excellence
 

Unity Project – A Moving Track

            Now, we learned to make a moving track, as a part of creating a 2D Simple Racing Game. How to make it:

  1. First of all you need to create a Unity Project 2D. See the following screenshot
  1. Download his assets. His channel provides all the sprites needed to create this game.
  1. Create 3 folders in your asset lists : Scripts, Sprites and Scenes.
  2. Drag a car and a track to your Sprite Folders.
  3. Drag your car to Scene View and immediately your car is a part of our new small game
  4. Now we need to put our track to the scene as well. But first, click on the Track, and on inspector change Sprites into Texture. Therefore, still in inspector, change wrap mode into repeat. Finally, apply
  5. On the screen, click on Game Object. Create a 3D Object named “Quad”. Put it on a Scene, and adjust it as if it were the track. Use Q-W-E-R
  6. Make a Directional Light there, adjust it your way then drag your track onto it. MAKE SURE that your track is a part of the quad you created before. Otherwise it will mess up with your script later on It pretty much looks cool for now
  7. Now the interesting part begins. We want to make the track move, so it will look as if the car moved. Create a C# script on your folder and let we begin
  8. Declare a public float variable so we can access it on inspector later on. Therefore, also make a Vector2 variable.
  9. On the update method, we want to change the vector of Quad (which in this case is the track) in Y coordinate. We don’t want the track to move horizontally, but we want it to move vertically. How much it changes depends on the variable velocity inputted later on. We use Basic Physics knowledge in order to think this out
  10. Now ultimately, we want to input that VECX variable into a texture offset. Enter this under that code

     GetComponent<Renderer> ().material.mainTextureOffset = vecx;

  1. On your quad track inspector, add your script to it. Set the speed the way you want, press play and BOOM, THE CAR IS MOVING. Although its actually the track that is moving

And there it is, my first time using Unity 5. I really am happy that I managed to do this simple thing. I’ll probably cover more Unity tutorials in my Article as I learn more and more. Thank you very much

Author:

  • Yogi Udjaja
  • Houwen Lie

Published at :

Periksa Browser Anda

Check Your Browser

Situs ini tidak lagi mendukung penggunaan browser dengan teknologi tertinggal.

Apabila Anda melihat pesan ini, berarti Anda masih menggunakan browser Internet Explorer seri 8 / 7 / 6 / ...

Sebagai informasi, browser yang anda gunakan ini tidaklah aman dan tidak dapat menampilkan teknologi CSS terakhir yang dapat membuat sebuah situs tampil lebih baik. Bahkan Microsoft sebagai pembuatnya, telah merekomendasikan agar menggunakan browser yang lebih modern.

Untuk tampilan yang lebih baik, gunakan salah satu browser berikut. Download dan Install, seluruhnya gratis untuk digunakan.

We're Moving Forward.

This Site Is No Longer Supporting Out-of Date Browser.

If you are viewing this message, it means that you are currently using Internet Explorer 8 / 7 / 6 / below to access this site. FYI, it is unsafe and unable to render the latest CSS improvements. Even Microsoft, its creator, wants you to install more modern browser.

Best viewed with one of these browser instead. It is totally free.

  1. Google Chrome
  2. Mozilla Firefox
  3. Opera
  4. Internet Explorer 9
Close