Making a race car positioning system

My game is nearly complete, I even have ai cars. I just dont know how to make a car positioning system for the players. I mean like 1st 2nd 3rd… Can somone explain how to do that? Im not asking for someone to just give me a script, I would prefer a tutorial of some type. As long as I understand whats happening in the script… C# please, but java is also acceptable. I know theres somthing in the asset store you can buy(its expensive), but im looking to learn, not own.

make gameobject prefabs, give them the tags “firstPlace” “secondPlace” etc

when you instantiate the cars, search for the gameobjects and use their transform to position the car.

Here’s one way I can think of:

1: Place checkpoints at regular intervals along the track. Put them in a ordered list of some sort, so you know their ordering.

2: Have each car know which checkpoint is the last one it passed. You can do this by distance checking, or by triggers, or something else that’s clever.

3: Rank cars by which checkpoint they passed last. If two cars’ last checkpoint is the same, rank them by their distance to the next checkpoint.

That should probably cover the basics. There’s a lot of fine tuning to do, but that’s depending on the game. Oh, and I think you’ll need a checkpoint just before and just after every turn to make this work - otherwise the distance calculations will be weird.

Hope that helps!

my idea would be then:
give a rank to each car

int rank;

that is initialized at the start according to position.
add a trigger collider / other proximity sensor to each car.

when 2 cars are in sensor (collider could be horizontal thin box, 90deg from the ground, creating horizontal cross with the road)
OnTriggerStay - monitor their position who is 1st by angle (/ shape means 2nd in before, \ sape means 1st is before)
OnTriggerExit - stop those calcs.

also, if box is thin enough and you dont need the updated rank every given sec you can just update when they leave trigger.

might be clumsy but it will give u an updated info in any given moment.

Hey, you could try my plugin which can handle all math. Its really simple to use you must add only 2 prefabs to your scene Unity Asset Store - The Best Assets for Game Making

if you need a solution check this link How to make a race position system in unity 3d ( Intermediate) - YouTube