Measuring relative distance?

Hello. I have looked at the docs for Vector3.distance, but I still cannot figure out how to do this. I want to measure the distance (of the x axis only) between objects A and B, where A acts as the origin, and then store that number as a variable.

For example: if object A was at (2,4,6) and object B was at (10,5,0), the variable’s value would be 8. But, if object A was at (1,2,3) and object B was at (0,0,0) the variable’s value would be -1.

Thanks

Hi Tofudude624 ,

Here you’re not using Vector3.distance and it wont help when you check for only one axis. you have to code yourself.
Its simple one here you have to subtract values from highest values. first compare two values then subtract.

ex : A(1,2,3) B(0,0,0)

if(A.position.x > B.position.x)
 {
   distance = A.position.x - B.position.x;
 }
 else 
 {
   distance = B.position.x - A.position.x;
 }