Race Positions

BlitzPlus Forums/BlitzPlus Programming/Race Positions

Ryan Moody(Posted 2004) [#1]
Hello,

I was wondering if anyone knew an algorithm (preferably in psuedo-code) which continually determines the race positions of cars on a 2D non-linear racetrack.

Thanks for the help!

Ryan Moody


MSW(Posted 2004) [#2]
Here is an idea on how to do it...works for 3D as well

Lace the track with a number of hidden checkpoints...hidden in that players never see them as they are only used by your game to deturmine race positioning...now arrange them from the start location to the finnish location....check point number one is right across the start line...number two further along the course, etc...then store a number with each car indicateing the last check point touched...so if the last check point touched was number 5 the next checkpoint the car should come across should be number 6 (if the car next touches check point number 4 it's going the wrong way).

Then just keep track of which cars have crossed which check points...calculate thier distances to the next check point (if more then one car is between check points...the closer the check points the less you have to do this))...and sort them starting from the highest check point crossed (and then closest to the next check point to cross) down to the lowest one crossed.


Rob Farley(Posted 2004) [#3]
One thing you need to do is make sure you multiply the lap checkpoint number by the lap number x total checkpoints, ie, if you've got 10 checkpoints, and you're at checkpoint 3 on lap 4 you want to record checkpoint 34, if you don't do this you'll get the person who's in the lead suddenly be in last place when he crosses the line (ie Checkpoint 10 to checkpoint 1).

In sphere racer I used this method, however, I didn't bother checking distances, I just updated the list every time any racer went over a checkpoint. There were 10 racers in sphere racer so someone hit a checkpoint at least every second or so and I thought that was good enough.


Ryan Moody(Posted 2004) [#4]
Thanks guys, your ideas seem like they'll work! I'll be using such an algorithm in my next project - "Wacky Races".
Look out for it in about a month's time!

Ryan