Distance measured showing negative values.

Hello,

I have a little problem, i just set up my 2d racing game so it calculates the distances between the ai players and the player. It works perfectly, and if i’m driving behind them, it shows their distance in meters.

Once i overtake them though, they will still show the distance (i guess that’s normal), but i really want to show it with a minus sign in front of it, since it’s negative distance now…

This is my code, is there some kinda way to make it show negative values?

function update (){

var ai : Vector3 = ai.transform.position;
var player : Vector3 = player.transform.position;

if (ai){

	var dist1 = (ai-player).magnitude;
	distance.text = "Distance to Green: " + Mathf.Round(dist1 / 3);
	distance.material.color = Color.green;

} 
}

InverseTransformPoint

e.g. : On the player->

var ai : Transform ;
function Update(){
   var relativePos = transform.InverseTransformPoint(ai.position) ;
      if(relativePos.z > 0)
          print("ai in front with positive distance stuff") ;
      else
          print("ai in back with negative distance stuff") ;
}