Racetrack Timers

Hi again and another noob question (or 16).

What would be the best way to do a racetrack lap timer? I also want it set up into sections so that each time the player passes a checkpoint, time is added to the timer a la OutRun.

To be clear, there are two timers… one for the overall lap time (and race time) and a separate one that counts down from a predetermined amount of seconds in which the player has to reach the next checkpoint.

Also, I’d need it so that the game knew if the player was going the wrong way so there could be no cheating the timers!

Cheers!!!

You’d have a float time value starting from 0 which you’d increment by Time.deltaTime in your Update() method. Then dotted around the track you could use trigger box colliders for waypoints. Each time the vehicle passed through the collider you would add some time to the timer and/or time the period taken between each waypoint. To know if the car was going the wrong way you could either number the waypoints and if they’re incrementing you’re heading in the right direction. Or look at the direction vector between the vehicle and the next waypoint. Trigger 0 would be the start/finish line and it would reset.

How can you pass through a collider?
Also are there any proximity sensors in Unity?

Your vehicle would contain a box collider. Each timer waypoint would be a box collider set to “trigger”. The vehicle player controller script would then monitor OnTriggerEnter messages and you’d update the appropriate variables.

For proximity sensors. Not directly, I would do them with a sphere collider and/or a squared distance check.