How to add progress bar showing player movement from start to finish line in 3d game ?,

I have added progress bar which is working fine for straight path. but in curve path as shown in figure the progress bar starts moving backwards due to decrease in z position of car.
I have added many check point to calculate the distance between them and added them.
but issue with current position. how to manage current position of car and move the progress bar.

public Transform LevelEndCheckpoint;
public Slider ProgressSlider;
private float totalDistance,current_position,playerPosition;
// Use this for initialization
void OnEnable () {
	playerPosition = this.transform.position.z;
	//totalDistance = LevelEndCheckpoint.transform.position.z -  playerPosition;
			for (int i = 0; i < p_Length; i++) {
		totalDistance += Vector3.Distance( AllPoints [i + 1].position , AllPoints *.position);*
  •   }*
  •   ProgressSlider.maxValue = -totalDistance;*
  •   ProgressSlider.minValue = -playerPosition;*
  • }*
  • void Update () {*
  •   playerPosition = -this.transform.position.z;*
  •   ProgressSlider.value = playerPosition;*
  • }*


Umm, since your game seems to be a racing game, why not have a simple float as the remaining distance and display that as a progress bar? For circular tracks, you can calculate the total distance, then calculate the remaining by substracting the distance covered.

Edit : to be clear, i’m not talking abour the distance covered by the car, but the track distance covered. You could have a car spin around and go backwards, the distance covered by the car would easily be greater than the total track length. Have to calculate the track distance covered by the car.