I am making some arcade kart racing game, and I developed a system to calculate the racer’s positions on the track. How I did this is I made some checkpoint triggers which span the width of the whole track. During the race, I increment a value in the lapCounter script every time a player enters the trigger of the upcoming checkpoint. I also have another value in the lapCounter script which calculates the distance (float) from the player’s own transform position to the next checkpoint position. So when the sort function sorts the list, it first compares two racers’ current checkPointValue to determine who is past the other. If both of those are the same, then I compare the distance to the next checkpoint for both racers, and the one with less distance is past the other player since less distance means closer to next checkpoint. Now this works alright and all, but I have a wide section of the track, and I had to place the checkpoints in the middle. The problem occurs that even if I am past the other player according to the direction of the track, the other player will still have a higher position than me if he is near the middle of the track. We are on the same checkpoint, but the distance magnitude between the player and checkpoint is smaller for him than for me.
A diagram:
So I was wondering if there is another way to calculate the distance to the next checkpoint or calculate racer positions that would be more accurate. Thank you for anyone reading this to take their time out of their day!