Build a Kart Racing Track Fast in Unity

posted in: Tutorials | 0

Do you want to make your own kart racing game? With Unity and its Splines tool, you can create custom tracks quickly. This guide will show you how to build a dynamic track from scratch. You’ll use the Shape Extrude feature and make a kart drive on the track. Video is below, while written tutorial is below that.

Getting Started

First, you’ll need a Unity project. The example project uses Unity 6 with the Polygon Street Racer and Polygon Pro Racer packs.

  1. Install the Splines Package: Go to the Package Manager in Unity. Search for and install the Splines package. Make sure you have version 2.7.1 or higher. This version has the property paths you’ll need.
  2. Create a New Level: Make an empty object and name it “Level One.” This will hold your track.

Creating the Track

Now, let’s draw the track using the Spline tool.

  1. Draw the Spline: Right-click in the “Level One” object. Go to Spline and choose “Draw Spline Tool.” Change the viewpoint to the top for a better view.
  2. Outline the Track: Start on one side of the level and click to add points. Click and drag to create curves (tangents). This makes the track smoother. Finish with a straight line. Press Escape when you’re done.
  3. Adjust the Spline: You can change the position of the spline points by clicking and dragging them. Reset the position to zero so it shows up better. Drag the spline into the “Level One” object.
  4. Create the Road: Make another empty object and name it “Road.” Add a Spline Extrude component to it. Then, add the spline container to the Spline Extrude component.

Shaping the Road

The default shape extrude is a circle. That’s not ideal for a road. Let’s fix that.

  1. Change the Shape: In the Spline Extrude component, change the shape type to “Road.” This makes the road flat with space on the sides.
  2. Adjust the Radius: Change the radius to fit your kart. You might need to add a kart to the scene to test the size.

Adding a Kart

Let’s add a kart to the scene to see how it fits on the road.

  1. Find a Kart: Find a kart in your assets. The example project uses a green kart from the Pro Racer pack.
  2. Adjust the Size: If the kart is too small, go back to the Road component and increase the radius.

Adding Material

The road looks plain. Let’s add a material to make it look better.

  1. Choose a Material: Find a road material in your assets. The Polygon Pro Racer pack has a good one called “roadmat 02.”
  2. Apply the Material: Click on the road and apply the material. The material adds a middle line to the road.
  3. Adjust Tiling (Optional): You can change the tiling to adjust the texture. But, this might not make the texture smaller.

Making the Kart Move

Now, let’s make the kart move along the track.

  1. Add a Camera to the Kart: Add a camera to the kart. Adjust the camera so it looks good.
  2. Add Spline Animate: Add a Spline Animate component to the kart.
  3. Set the Spline: Copy the spline to the Spline Container in the Spline Animate component.
  4. Set the Duration: Change the duration to set the speed. Try 15 seconds to start.
  5. Set the Loop Mode: Change the loop mode to “Ease In Then Continuous.” This makes the kart speed up smoothly.

Now, press Play. The kart should drive around the track.

Adding Trees

The track is still a bit boring. Let’s add some trees to make it more interesting.

  1. Create an Empty Object: Make an empty object and name it “Outer Trees.”
  2. Add Spline Instantiate: Add a Spline Instantiate component to it.
  3. Set the Spline: Add the spline container to the Spline Instantiate component.
  4. Add Trees: Add several different types of trees. You can use trees from the Polygon Pro Racer pack.
  5. Adjust Instance Count (Optional): If you want a specific number of trees, use “Instance Count.” You can set an exact number or a random range.
  6. Set Linear Distance: Change the mode to “Linear Distance” and set it to “Auto.”
  7. Add Position Offset: Add a position offset on the X-axis. This spreads the trees out. Set it to a random range.
  8. Add Rotation Offset: Add a rotation offset to make the trees look different. Set it to a random range.
  9. Add Scale Offset: Add a scale offset to change the size of the trees. Set it to a random range.
  10. Randomize: Click “Randomize” to change the trees.

Now you have trees on the outside of the track. You can duplicate this to add trees to the inside. Just change the position offset to negative numbers.

Adding a Barrier

Let’s add one more thing: a barrier.

  1. Add Spline Instantiate: Add another Spline Instantiate component.
  2. Add a Barrier: Add a barrier prefab.
  3. Adjust the Forward Axis: Change the forward axis to X-.
  4. Set Linear Distance: Increase the linear distance until the barriers cover the width of the road.

Now you have a barrier along part of the track.

Test and Tweak

Hit play and test your track. Change the curves, elevation, signs, cones, and barriers.

Ready to build your own racing game? Use this guide to get started and create something awesome!

Comments are closed.