March 18, 2015

How to make race tracks that twist and roll and twirl in Unity and Blender

Today I got the question on how to make race tracks that twist and roll and twirl in Unity. So that's what we are going to learn here. I believe the best solution to the question is not to make the track in Unity. You could make it in Unity, but if you are a beginner it is much easier to do it in Blender, which is also a free software. So step 1 is to download Blender.

Now let's make a track path. The good think with Blender is that it uses the same coordinate system as Unity, so 1 unity in Blender is 1 m in Unity. So make a square with the size you want. You can maybe use the cube Blender starts with, click on Edit Mode and drag the small vertices to the shape you want. Don't forget that it also needs a depth, and the depth of the shape you made will also determine the resolution. But don't worry if you mess up, you will be able to change it later.

Next step is to make the path that twist and roll and twirl. We will here use a so-called Bezier curve. So click on Add → Cuve → Bezier. You can edit this path, and make it more complicated by going to Edit Mode, select one vertice, and then click "E" for extrude. With this curve you can also control the angle of your path. So if you want those NASCAR sloped curves, then experiment with the handles (the small lines that go out of each vertice). 

But a path and a track part makes no racing track. We need to connect them. So select the path (cube), go to Modifiers (the wrench on the right side). Now you need to add 2 modifiers:
  • Array modifier. Select Fit Curve in Fit Type, and select the curve in the box below.
  • Curve modifier. Select the curve in the Object square. You might have to select another deformation axis
Everything should now look like this:

The good thing with Blender is that Unity and Blender are very good friends. So to export the track to Unity you just have to save it in the same directory as your Unity project. Then you have to drag it into your scene. The last thing you have to do is to click on the child to the track object, pick the child that's the track (and not the Bezier) and add a Mesh Collider to it. Now the track should be drivable like this:

No comments:

Post a Comment