How to implement laps around a track?

I’ve done some searches, but maybe I’m not using the correct terms on what I want to do, so let me explain. (Please excuse my bad english.)



We’re developing a game based on the movie Death Race for a course at uni; for the semester we’re mostly out of time to develop any huge features, but there are some basic ones that are still missing, for example, counting laps around the track and ensuring the player doesn’t win by going back and forth through the finish line (in a normal race mode kind of way).



I’d like to include this into the game but have been looking around for ideas and haven’t found any so far on how to implement this.

So, any thoughts/suggestions on what to do? I’d really appreciate some help.

One suggestion I could offer would be to setup a some type of way point system. If someone make a lap, then need to reach the next way point. once the way points have been checked then a lap could be made.



Just my 2 cents, haven’t made it that far myself, but makes sense to me.

Put a few check points around the track that the player must pass through sequentially. Once the player has passed through them all and crosses the finish line, one lap is complete so reset the checkpoints. (These checkpoints do not need to be visible or made known to the player) These points could just be world vector positions in the middle of the track. Every update check to see if the player position is within full width of track / 2 of each checkpoint position , if so then mark it as passed.

1 Like

I’d add a bit more fuzziness on the checkpoint than that just to make sure there are no chances of accidentally missing the player passing through it if the framerate is low or similar. Make the checkpoint cover a decent length of track.



One checkpoint would allow a player to go half way around and then turn back. Two check points + finish line all passed in order is enough though. Just store a checkpoint counter in the player, when they hit a checkpoint if (player.lastCheckPoint() == this.checkPoint()-1) player.setLastCheckPoint(this.checkPoint());



Then finish line just does the same check but instead does: player.incrementLap(); player.setLastCheckPoint(0);