I’ve made a basic traffic system in my app. It involves my vehicles following a simple path, and that’s all they do - follow the path. When they hit any certain node, they get shot off onto another path, and that’s that. Same applies for spawning and destroying, etc. They don’t use physics at all; they’re kinematic, path following bots.
The problem I’m facing now is how the cars collide with each other. Each vehicle contains a solid mesh collider (“solidLayer”) and in front of each car is a capsule trigger collider (“triggerLayer”). These colliders are in different layers, and ignore any other collision in the game. The vehicle movement script defaults to GO movement, and if OnTriggerStay() is called, the vehicle slows down (brakes).
Everything works fine, but sometimes a vehicle doesn’t slow down in time, hitting the car in-front of it, causing them to partially overlap with each other. When this happens, OnTriggerStay() is sometimes called for both vehicles. They’re both permanently braking, causing the traffic system to fail (cars behind just queue up in line).
Is there any way I could cheat the system and prevent this from happening, or at least how to elegantly handle this? There’s many things I could do - for instance, I could just toss out both cars and return them to the object pool from which they came. However, this would look funky (disappearing cars!) and doesn’t look professional. Another way could be to reduce the amount of cars on the road and increase the duration of the spawn points, but that’s just trying to make the situation occur less often then dealing with it correctly.