Your devlog is very detailed! Wishing you all the best with finishing this game up - it looks like a great learning exercise.
Simplifying code (or how to complicate things further)
I then remembered that there was a comment suggesting that I use the function transform.Forward. I understood it to mean that I could save lots of lines of code. Long story short, it didn't really help and if you want to see the comedy results in trying to make it work, go ahead and check out my latest video DevLog here:
I know nothing about Unity specifically but here's my interpretation of what the transform.forward code is doing, assuming Unity behaves how I would expect it to
. I didn't see any explanation like this in the youtube comments so it might be helpful to learn what went wrong.
rb.velocity = civTruck.transform.forward * forwardSpeed
"rb.velocity =" is setting the velocity of the rigid body. This is overriding any velocity that the physics system has previously calculated which is why the cars no longer seem to care if they collide with the player's vehicle and keep pushing forwards, and are no longer affected by gravity, etc.
transform.forward gives you the current forward vector of the car. So the result of this code is simply to make the car move along that forward vector at the "forwardSpeed" speed. If the car is perfectly flat on the road and pointing in the right direction then that's fine. But as soon as the car starts to point in a different direction, it'll start to move in that direction instead. Cars that point slightly into the air will start to fly and cars that point down to the ground will keep pushing down into the ground.
Rigid bodies also have a rotational velocity (how fast the angle is changing) which isn't being overridden like the velocity is. So if the car is hit by something it may start to spin according to physics. This explains the behaviour where the cars are floating through the air but still freely spinning.
If you do still want to improve this area of the code: I would suggest splitting the problem into first deciding where the car
wants to be (a position in the correct lane of the road but further along it?), then some combination of turning or moving towards that target position. The Unity rigid body should have some kind of function like "ApplyForce" or "AddForce" which would be the correct way to influence the car's movement without overriding the velocity completely.
Alternatively there may well be some useful feature already built into Unity that would allow the car to navigate itself in a smarter way? (Or, as a last resort you could just have any cars that stray off the road explode, then they're no longer a problem
)