Skip to main content
GameDev.net gamedev.net
🔒 Locked

best way to check checkpoints and distance

Started by ghiboz Apr 21, 2012 at 8:23 AM 4 replies 2.2k views
Original Post
ghiboz
ghiboz
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

thanks in advance smile.png
Krohm
Krohm
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?
Previously "Krohm"
Washu
Washu
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 %
In time the project grows, the ignorance of its devs it shows, with many a convoluted function, it plunges into deep compunction, the price of failure is high, Washu's mirth is nigh.
ghiboz
ghiboz

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
Washu
Washu
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.
In time the project grows, the ignorance of its devs it shows, with many a convoluted function, it plunges into deep compunction, the price of failure is high, Washu's mirth is nigh.
ghiboz
ghiboz
thankyou!
i've found this and works fine!
http://stackoverflow.com/a/9557244/349045

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.