Jump to content
  • Advertisement
Sign in to follow this  
Kiran Viraktamath

How to find position(Rank) of the user car

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

If you intended to correct an error in the post then please contact us.

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 this post


Link to post
Share on other sites
Advertisement
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 this post


Link to post
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 this post


Link to post
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 this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!