# How can I get the distance between two points, but in just one relative axis?

Because is one relative axis, vector3.distance doesn´t work. Those points are collision points, and if the object that receives them is rotated, then that distance is diagonal. I want to get its relative x axis distance from collisions.

Distance along the x axis is merely the absolute value of the difference (subtraction) of the x coordinates.

@JVene correct me if am wrong, but I think that Vector3.Distance takes the distance like the red line:

And I need the blue one, which i can´t get by substracting the x coordinates like you say, because that would give me something like this:

What you're looking for is a local relative X axis (local being key to recognizing what you're looking for). Your diagram is the most informative on this point, as I'm not entirely sure there's a clear label.

Note, by your diagram, the blue line will be the width of the rectangle, so if you know that you can just take it. Otherwise, your solution is trig, but could be be basic Pythagoras, in a sense. The distance of the red line is the hypotenuse. Unfortunately, you next need the base (the line of the implied triangle you haven't drawn). That is the distance of apparently the local y coordinates of the two points, from which you can algebraically swap Pythagoras around a bit to get the other leg.

On the other hand, you have a right triangle. If you could calculate the angle between where the red and blue meet, you can deduce the rest (the third is 90), and with the length of the red line you can use law of sines to complete the triangle and thus know the blue line length.

However, you might find it simpler to "unrotate" the object itself, or more accurately, unrotate the two points to a world axis alignment. Then the blue line would be merely a subtraction of the x coordinates.

Thanks for your detailed explanation. I also thought making use of trigonometry the same way you did. However, depending on the leg of the triangle, the use of sine or cosine was different. I was having trouble identifying which to use, since the points may differ from the diagram and sometimes I will get them only when the object is rotated and other things that really confused me. But then you say there´s a simpler solution, "unrotate to world axis alignment". How can I achieve that?

### Your answer

### Welcome to Unity Answers

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.