# best way to check checkpoints and distance

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

## Recommended Posts

hi all!
i have a question about my racing game..
I need to understand the position (in percentage or by distance) of the road driven and also check some checkpoints..
In my mind the checkpoints maybe solved by distance (checkpoint #1 at 12,3% for example)

what's the best way (and fast to calculate) to do this?

I've tried with bezier, but is hard and slow find a tangent point...
actually I've some points that represents the centerline of the road

##### Share on other sites
I'd totally give up the idea of distance and just have a collidable sensor signal me when the player passes through them.
But perhaps you also want to give the player an estimation of the distance to the next checkpoint. Is that the case?

##### Share on other sites
If we're talking a race track... just have the checkpoints represented by a plane. Then the checkpoint is "hit" when the player's vehicle intersects the checkpoint plane.

If you also want to represent the % around the track the person is at, then simply have a series of line segments that represent the track. Then the nearest point on the line segments is where they are (completion wise) and calculating the total % complete is trivial. Should take care to handle the case of skipping a checkpoint though when calcuating said %

##### Share on other sites

I'd totally give up the idea of distance and just have a collidable sensor signal me when the player passes through them.
But perhaps you also want to give the player an estimation of the distance to the next checkpoint. Is that the case?

thanks for this info.. interesting

If we're talking a race track... just have the checkpoints represented by a plane. Then the checkpoint is "hit" when the player's vehicle intersects the checkpoint plane.

If you also want to represent the % around the track the person is at, then simply have a series of line segments that represent the track. Then the nearest point on the line segments is where they are (completion wise) and calculating the total % complete is trivial. Should take care to handle the case of skipping a checkpoint though when calcuating said %

thank you, so for example a simple line between my 2 points and calculate by tangent the nearest point... have you got some example to read?

thanks again

##### Share on other sites
You can google up on finding the nearest point on a line to another point. Then you simply calculate that value for all line segments and the value with the smallest distance is the closets one along the entire set of line segments representing the race track.

Alternatively, since you know which line segment they started on (the start of the race was in that segment, you can simply calculate the nearest point on the current line segment, the previous line segment, and the next line segment.

Since the line segments should be in order (from start -> next -> next -> next -> finish) you can simply take the point you find and the sum of the distances of each preceding line segment all over the total of the sum of the length of all line segments to get the % completion.

##### Share on other sites
thankyou!
i've found this and works fine!
http://stackoverflow.com/a/9557244/349045

1. 1
2. 2
3. 3
Rutin
18
4. 4
JoeJ
14
5. 5

• 14
• 10
• 23
• 9
• 41
• ### Forum Statistics

• Total Topics
632634
• Total Posts
3007556
• ### Who's Online (See full list)

There are no registered users currently online

×