Knowing player order from only the finish line requires that you store two things when they cross the line:
1) The last time at which the player crossed the finish line
2) The number of laps the player achieved
Then you can tell if a player is beyond another by doing the following test:
if player_a.lap_count == player_b.lap_count:
# Players are in the same lap but one was late
if player_a.lap_time > player_b.lap_time:
# Player A is first
else:
# Player B is first
# Note: if a car takes the lead over another during the same lap,
# this code won't detect it, which is why solution 1 would be better.
elif player_a.lap_count > player_b.lap_count:
# Player A is first
else:
# Player B is first
And then if you need the order as a list, then get all layers as an array, and use the sort_custom
function using the code above.
It's not very accurate for a racing game though. You could even this out by adding checkpoints maybe (or many many invisible checkpoints), but the most accurate solution would be 1.
You can alternatively use the travelled distance since last lap/checkpoint instead of lap_time
, which would be more accurate but still biased because not based on the road curve.