# racing position?

hay!
does anyone have any tuts on how to tell which position you are in a race?

well, if the race is just a straight line along the (x axis for example), you could just compare the x values. if it is a track, compare who has gone through more laps>checkpoints. if you use laps and checkpoints, you can also check the distance to the next checkpoint for greater accuracy. example:

``````if carA.laps &gt; carB.laps:
carA.place = 1
carB.place = 2
elif carA.laps &lt; carB.laps:
carA.place = 2
carB.place = 1
else:
if carA.cp &gt; carB.cp:
carA.place = 1
carB.place = 2
elif carA.cp &lt; carB.cp:
carA.place = 2
carB.place = 1
else:
if dist(carA,checkpoints[carA.cp+1]) &lt; dist(carB,checkpoints[carB.cp+1]):
carA.place = 1
carB.place = 2
else:
carA.place = 2
carB.place = 1
``````

OK, i know i could have made this better (ie. more complicated, harder to understand, using loops for an unlimited number of carsâ€¦) but this is not code for you to use in a game. (although you could try if you want. you will have to make your own distance function though.) it is just to illustrate my idea.

I recently had the same problem. When there are only two cars you can solve it with expression controllers and some checkpoints. When there are more cars best way is to get someone to write a script for you. I used logic bricks and it got a bit complicated. Check out my blend file for my solution.
Hope this helps