How to find position(Rank) of the user car

This topic is 3339 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

Recommended Posts

Hello All, I am working on a Racing game, I need to find position of the user car , i.e. rank of the user car amongst the opponent cars. I know one technique that by using check boxes on track. But i want to know the better method to find user rank and update to display the position on each frame. Can anybody please help me out in this? Thanks in advance,

Share on other sites
Well, just an idea:
1. Take the ideal line (as a spline, line segments or whatever).
2. Project the positions of each car onto it.
3. Now you have all car positions in one dimension.

Share on other sites
A fairly cheap method may be to keep track of the distance traveled by each car. E.g., after each frame update, car.distance += car.speed*deltaTime. If you keep the distances and car numbers in a list, update the distances in the list* and do a bubble sort to reorder the list. Because there will be very few changes in a single frame, the sort will be quick, only one or two swaps, if any.

*list.distance = car[ list.carNumber ].distance

Share on other sites
Personally I would go with the 'project onto spline' method rather than the accumulated distance method.

The latter method, I think, will give incorrect results in quite a few cases. For example, consider a car driving around the inside of a circular track, and another driving around the outside of the track, but at a greater speed so as to keep pace with the inside car. Even if the inside car is tied with or perhaps even ahead of the outside car, the outside car may be incorrectly considered as being in first place. Or, imagine one car driving straight down a straight track, while another car swerves back and forth, but at a greater speed, again keeping pace with the first car. Again the second car will be considered to be in first place even though the cars are tied. (The 'projection' method, on the other hand, should handle both of these cases correctly.)

Share on other sites
Thank you VanKurt, I wil try what you suggested , currently i am working on AI after that i wil try your method.

• What is your GameDev Story?

In 2019 we are celebrating 20 years of GameDev.net! Share your GameDev Story with us.

• 13
• 11
• 15
• 11
• 12
• Forum Statistics

• Total Topics
634151
• Total Posts
3015839
×