I have a single lane road and I want cars to drive along it. I want variables such as car speed and gap lengths between cars to be changeable.
I have already implemented this simply using a Waypoint circuit along the road and spawning cars at one end of the road every few seconds, destroying them once they get to the end of the road. I am also able to change the speed of the cars.
However for choosing a gap length between cars, this implementation isn't great. I thought I could use the spawn time (e.g. 3 seconds between cars means a certain gap length) but this isn't accurate when you factor in realistic acceleration time and the speed. For instance, if the speed is 100mph and cars are spawned every 3 seconds, the first car spawned is going accelerate quickly and be a lot farther than the second car when it spawns. If the speed was 30mph with a 3 second spawn time, the cars are going to have a much smaller gap. I want to be able to predetermine what this gap is going to be regardless of the speed limit.
Any ideas how I can go about this? An idea of mine was that I could populate the road with cars, making sure that the length between the cars are the predetermined gap length and begin the simulation from there. But how do I make these cars follow the same Waypoint system? And how do I properly spawn new cars to keep a constant flow of traffic as the cars at the end of the road are destroyed?