<aside> 💡 In this tutorial, you’ll to learn to add NPC traffic to the scene, and change their speed settings.
</aside>
Let’s add some NPC traffic to our T-Junction level. Adding traffic is quite easy:
First, you should have a road that terminates into a Gate section—namely, a tunnel—that is able to spawn NPCs. Select it in the scene.
You should see a green orb floating in front of the tunnel. This represents the starting point of our NPC traffic. Click on it, and you’ll see a green arrow appear between the orb and the mouse cursor.
As you drag the green arrow, you should see green orbs appear in front of any other Gates in the scene. Let’s connect the green arrow to the other tunnel in our level by clicking on the tunnel’s orb. You’ll see that an arrow is now formed between them. This means that a potential NPC path is now created into the direction of the arrow.
Now add a similar arrow from the other tunnel to the first one. Now we have two potential NPC paths, one for each lane.
We’ll still have to populate that NPC path. When you have a tunnel selected, you should see Generate Traffic and Remove All Traffic buttons on the right side of the viewport. Press the Generate Traffic button, and you should see an orange line appear for each lane, representing streams of NPC traffic.
Now you should have a road that will have NPC traffic in-game!
This might be a good moment to export and playtest the level. (To do this, have Turbo Dismount 2 open. Then, over in Unity, press the Export Level button in the Toolbar. Go back to Turbo Dismount 2, and click the My Level card in the Level Menu’s Workshop tab.)
<aside> 💡
Note: in more complex road configurations, you’ll need to specify the direction that the NPCs will drive in on each lane. Do this by clicking on a tunnel block, and then click on the green arrows next to it. The direction of the arrows must match the intended direction of the flow of traffic.
</aside>
Next, we can adjust some traffic-related settings, including speed limits and what vehicles should be spawned. There are also more advanced settings where you can affect the specific timing for how the NPCs will spawn. It looks like our traffic is a little bit slow for our purposes, so let’s make them drive a lot faster!
Each road segment has its own speed limit that NPCs obey. When you select a road segment in the scene, you’ll find its current speed limit in the Traffic Block component in the Inspector window. When you click on the Speed Limit drop-down menu, you’ll find a range of different speeds. We can change the speed to 120 km/h for now.