<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.
If you have other tunnels in the scene your selected tunnel is connected to by a road, a green orb should now appear in front of them as well. Let’s click on the other 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.
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.
<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. Unlimited is the fastest one, making NPCs drive as fast as their engines will allow!