I'm working on a top-down racing game and I want to know which car is the leader.
My checkpoints are colliders spread along the road.
In the example, there are 5 checkpoints (let's call them c0, ..., c4). 3 laps must be completed for the race to end.
My current algorithm creates an array like this
[c0, c1, c2, c3, c4, c0, c1, c2, c3, c4, c0, c1, c2, c3, c4, c0]
for each car. Each car keeps an index of where it is at the moment and this index is updated when the car touches a checkpoint.
The problem is that if some cars have the same index, the game doesn't know which one is the leader. Is there a better approach to track the leader than mine?