
There are many ready made solutions for traffic AI on the Unity Asset Store. iTS Traffic System, TI Traffic AI, A.I Car Traffic PACK, just to name a few.
But if you are asking me the best way to do this is to write your own code from scratch.
When you have to deal with traffic in an open world game where you want to mess around and cause some chaos, control over your code is very important.
To save time I tried two of the above ready made solutions, but apparently I lost more time than the time I needed to write my own code that actually works the way I want.
I don't say that those assets are not good, they are actually great and very professional but apparently they are not what I needed.
To get started with my script I used waypoints to make the cars follow a path. I created a script that spawns the cars on each waypoint and only when the player is at a certain distance.
The cars dynamically follow the closest waypoint weather they are on the right or on the left side of the road. They will also stop if they find any obstacle in front of them. It sounds very simple but it does the job right.
To be continued...