# Unity - Level complete progress bar stops at 75%

I am trying to build a progress bar that indicates the completion of the current level from 0 to 100% (or from 0 to 1 in probability). I found this example:

https://stackoverflow.com/questions/34960494/distance-from-start-point-to-end-point-in-percentage-in-update

It works, but my progress bar stops at about 75% when i reach the target position and then it drops down. This is my code:

public GameObject player;
public GameObject target;
public Text scoreText;

private float startDistance;
private float currentDistance;

private void Start()
{
this.startDistance = Vector3.Distance(player.transform.position, target.transform.position);
}

private void Update()
{
this.currentDistance = Vector3.Distance(player.transform.position, target.transform.position);
float percentage = 1 - (currentDistance / startDistance);
transform.localScale = new Vector3(percentage, 1f, 1f);

this.scoreText.text = string.Format("Score: {0}%", Mathf.Round(percentage * 100f));
Debug.Log("Percentage Completed: " + (percentage));
}


The player moves by himself towards the target position at constant speed without acceleration. The player can move its character left or right in order to avoid obstacles. This doesn't change the player's speed, it just maneuvers the direction. Maneuvering, I realized the progress sometimes goes beyond 75% and sometimes below. Why is this happening? How to make the progress simply reach 100% when I reach the target position?

• It sounds like your distance never reaches zero. Have you verified that your player is reaching the target position on every axis, or tried zeroing out the component of the separation that's parallel to the camera's view axis? – DMGregory Oct 13 at 18:23
• @DMGregory it seems like it never reached the target because it was a game object. But when i added a cube as the target, the progress was correct. Do you know why? Why does an empty game object react differently to a cube? – busuu Oct 14 at 19:24
• There is no fundamental difference between an empty game object and a cube — they both have a transform, and that's all you're using here. So the change from an empty object to a cube was not itself the fix. But you did something different when you placed your cube (maybe placed it on the same plane as the player character, rather than separated from it on the z axis?) which fixed the issue as a side effect. – DMGregory Oct 14 at 19:28