# Traffic 1. Draw each lane as a **DRC Traffic Lane** (a spline, in the direction cars drive). Set **Speed Limit** and **Next Lanes** (where it can go at its end; a car picks one at random). **Set the spline points to Curve Clamped.** With the default tangents, where a long straight meets a short bend the spline overshoots the corner and comes back, and cars leave the road there. 2. Where lanes cross, place a **DRC Traffic Junction** and size its **Area** to cover the crossing. List the lanes with the right of way in **Priority Lanes** (empty: everybody gives way). **Stop First** makes the others stop at the line first, like a stop sign. Where a road has two lanes or more the same way, set each lane's **Left Lane** and **Right Lane** to the one beside it: cars change between them (see Changing lanes below). Or turn on **Traffic Lights** and list every lane through it in **First Light Lanes** or **Second Light Lanes** (see Traffic lights below). 3. Place one **DRC Traffic Manager**. Set **Vehicle Classes** (each with a **Spawn Weight**: 3 against 1 spawns three of one for each of the other; empty: plain `DRCVehicle`), **Max Cars**, **Spawn Radius**, **Min Spawn Distance** (not under a player's eyes) and **Despawn Radius**. The manager runs on the server. Traffic cars are ordinary vehicles with no controller: clients draw them and predict them near a player like any other vehicle, and a player can get in one (it then leaves the traffic). How a traffic car drives: - It steers back onto its lane like a self-driving car does (Stanley): by how far it points off the lane a little ahead, plus a pull back to the middle that grows with how far off it is and shrinks with speed (**Lane Hold Strength**). - It takes bends with no more than **Corner Grip** (0.35 g) of sideways pull. - It keeps **Stop Gap** plus **Follow Time** behind the car ahead on its lane, braking at **Comfort Braking**. - It stops for players, people and their cars in front. When what stopped it does not move for **Pass Wait Time** (3 s), it goes round by the other way's lane (**Pass Offset**, 4 m left) at **Pass Speed** (20 km/h), signalling out and back in, if that lane is clear from here to **Pass Clear Distance** (70 m) past it and the pass ends before the next junction. Otherwise it keeps waiting. **Pass Stopped Obstacles** turns it off. - Where its lane splits it turns on the signal for the way it takes, 30 m before and through the turn. - At a junction without the right of way it stops 3 m before the area and goes when the area is empty, no car with the right of way is less than **Clear Time** (3 s) away, and it is its turn. With the right of way it goes through, but waits for a crossing car still in the area. Nobody goes in without room for the whole car past it. - Stopped behind a player (on foot or driving) for **Honk Delay** (1.5 s), it honks once. - After a crash (its bodywork took damage) it honks, stops, and stands with its hazard lights on for **Crash Stop Time** (6 s) before it goes on. - A car stuck for **Stuck Despawn Time** (30 s) far from every player, or on its roof, is removed. Every car gets a driver of its own when it spawns, under **Drivers**: - **Speed Variation** (0.1): it drives the speed limit times 1 plus or minus up to this. - **Follow Time Variation** (0.3): it keeps Follow Time times 1 plus or minus up to this. - **Max Aggression** (0.3): it is pushy from 0 up to this. A driver at 1 takes bends with half again Corner Grip, brakes twice as hard as Comfort Braking, follows 40% closer and waits 60% less before going round something. In the example town (30 cars, 60 s, no network), the fastest tenth of the cars drove 39.8 km/h with every driver the same, 41.8 with the defaults and 44.6 with Max Aggression 1 and Speed Variation 0.25; no two cars touched in any of them. Measured alone (no network), two two-way loops crossing in four junctions, 40 cars, 150 s: no collisions, no car removed for being stuck, 50 km/h on average (60 km/h limit), the longest wait 25 s (giving way to a busy road). Cars kept within 46 cm of their lane. Driving 30 cars costs the server about 0.23 ms a frame, on top of their physics. Measured with a car parked in the middle of a town lane, 30 cars, 120 s: 6 cars went round it, none touched it or another car, and the longest any car waited anywhere was 11 s. Measured in the example town with the player standing in a lane and one car damaged at 20 s (30 cars, 60 s): three cars, one after another, waited behind the player, honked and went round; the damaged car honked, stopped and stood with its hazards on; no two cars touched. ## Traffic lights A junction with **Traffic Lights** on ignores Priority Lanes and Stop First. Its two lights take turns: **Green Time** (12 s), **Yellow Time** (3 s), then **All Red Time** (1.5 s) red both ways, then the other light. **Cycle Offset** shifts a junction's cycle so neighbours do not change together. - On green a car goes through, unless it turns left: then it gives way to the other direction's green, as at a junction without lights. It still waits for a crossing car left in the area and for room past it. - On red it stops at the line. On yellow it stops when it has room to at Comfort Braking; too close, it goes on. - The lights run on the server's clock, so every machine shows the same without anything sent: **Get Light**, **Get Light For Lane**, or **Get Light At** (static) to draw lamps where there is no junction (clients have none, junctions are the server's). The example town draws its lamps that way. Measured in the example town with four junctions on lights (30 cars, 120 s, no network): 62 cars went in on green, 3 on yellow (too close to stop), none on red; no two cars touched; the longest any car waited was 18.7 s. ## Changing lanes On a lane with a **Left Lane** or **Right Lane** (and **Change Lanes** on, under Lanes): - A car getting on it picks its next turn among this lane's and its neighbours' next lanes. A turn that leaves from the lane beside makes it move over first; if there is no room before the lane ends, it takes a turn from where it is. - Behind a car that is moving but slower than **Slow Car Share** (0.85) of what it wants, for **Pass Slow Car Time** (2 s), it moves over to pass (left first). A queue standing at a junction is not passed. - It moves over only with room on the lane beside: **Lane Change Gap Time** (1.5 s at the speeds involved) ahead and behind, on top of the cars' lengths and Stop Gap, nobody else there, and at least 15 m before the lane ends. It signals while it moves. - **Set Driver** (server) gives one traffic car a driver of your own, for a slow truck or a reckless one. In the example town the horizontal street through the middle is an avenue, two lanes each way (the outer one straight or right, the inner one straight or left). With one car on it slowed to 40% of the limit (30 cars, 120 s): 12 lane changes, one of them passing the slow car, no two cars touched.