Proximity Along Local Axis

Hi everyone,

Thanks in advance for your insight! Game object A is a child of another object. I need to find the distance between game object A and game object B. That’s no problem using Vector3.Distance. But my challenge is this: I need to figure out the distance from A to B along A’s local x axis only. I script with C#.

I would really appreciate any feedback on this! Many thanks.

You can use A.InverseTransformPoint(B.position) to get B’s position in A’s local space. This gives you a Vector3, and the X component of that result should be what you’re looking for.

1 Like

Yaaas! That’s what I needed. Thank you very much!