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,
How to find position(Rank) of the user car on Racing game
Started by Kiran Viraktamath, Dec 03 2009 11:59 AM
4 replies to this topic
#1
Posted 03 December 2009 - 11:59 AM
#2
Posted 03 December 2009 - 01:45 PM
Imagine an invisible line at the center of the road that extends all along the track. At the start of the line a car has the value is 0.0. At the end of the line, a car has the value is 1.0. You can think of this as the car's progress. As it nears the finish line, it reaches the 1.0 mark. A car's position on that line is always parallel to the car's actual position. This is the closest point on the line and is easily determinable. The rank of each car is then their sorted position in the array. While creating the array you could use an insertion sort to speed things up.
Naturally your track is going to have curves, so a straight line isn't feasible. You can upgrade the solution to use a series of cubic or quadratic bezier paths instead. In fact, you could use a bezier path to create your track to begin with. The unique thing about paths is that they can follow the principle that 0.0 marks the beginning of the path and 1.0 marks the end of the path, thus the solution above still works, albeit you must use a different algorithm to calculate the closest point on the path.
Naturally your track is going to have curves, so a straight line isn't feasible. You can upgrade the solution to use a series of cubic or quadratic bezier paths instead. In fact, you could use a bezier path to create your track to begin with. The unique thing about paths is that they can follow the principle that 0.0 marks the beginning of the path and 1.0 marks the end of the path, thus the solution above still works, albeit you must use a different algorithm to calculate the closest point on the path.
http://www.nutty.ca - Being a nut has its advantages.
#3
Posted 03 December 2009 - 07:43 PM
i would go for a function integrated along the curve
obviously as the nut said , you should have the points forming that curve, then its simply a matter of choosing s uitable integration algorithm
obviously as the nut said , you should have the points forming that curve, then its simply a matter of choosing s uitable integration algorithm
#4
Posted 04 December 2009 - 03:48 AM
A less math oriented and more brute force approach would be to have mini "check points" and whom ever gets to that spot first is in first and so on. (You would want to implement some kind of check to make sure they got there honestly, that is, without cheating.)
The draw backs are numerous, but it will save you from a little math if you are hesitant about that. You could possibly, depending on how processor intensive the math is, have a small speed hit. I don't think it would, unless you had a really big track, change the memory consumption too much.
Another would be that you wouldn't get the same "instant gratification" that you would for the previous method. But if you have a "check point" every third tile or something, it wouldn't be too noticeable.
Just an idea, although this is probably a really bad method.
The draw backs are numerous, but it will save you from a little math if you are hesitant about that. You could possibly, depending on how processor intensive the math is, have a small speed hit. I don't think it would, unless you had a really big track, change the memory consumption too much.
Another would be that you wouldn't get the same "instant gratification" that you would for the previous method. But if you have a "check point" every third tile or something, it wouldn't be too noticeable.
Just an idea, although this is probably a really bad method.
/* Perfect_day.c */
#include <arcade>
#include <computer>
#include <drinks>
#include <hardware/high_end>
#include <snacks>
#pragma <responisiblities>
...........
#include <arcade>
#include <computer>
#include <drinks>
#include <hardware/high_end>
#include <snacks>
#pragma <responisiblities>
...........
#5
Posted 04 December 2009 - 04:10 AM
Thank you all, I wil go for projecting the all cars position on ideal invisible line method. currently i am working on AI after that I wil try this one .
1 user(s) are reading this topic
0 members, 1 guests, 0 anonymous users











