He said he â€śchecked with a raycast that its 3m awayâ€ť which means he used a raycast once and it seemed to have worked fine, but he didnâ€™t say why that method was not what he wanted.

Subtracting the two will also just get the distance from the two objectâ€™s origin points, guessing from his images and explanation he doesnâ€™t want.

I think your wall has made me more confused, but I think I understand what you want from your second attemptâ€™s code. What does it give as the distance when you use that method to flatten the distance? By all means it looks like the math should work out.

I see. Now I really understand what you want, you want the distance between a point and a plane. You canâ€™t get the distance you want with just 2 points as input, you need the rotation to be able to calculate this, or some other way to define which â€śwayâ€ť the plane is facing. Plenty of math formulas online showing you how to do that.

Well, you do understand that a raycast hits the surface of the wall while using the â€śpositionâ€ť (whereever you get that from) may be behind the wall, so further away. So what exactly is the given information and what do you want to know. The Distance method does return the correct distance. Flattening on the x-z plane is also correct if youâ€™re just interested in that horizontal distance.

A raycast would almost always return you something different unless the â€śpointâ€ť youâ€™re referring to is actually at the surface of the wall. Though even then, where did you raycast against the wall? A wall has size and it matters where you hit it. If you hit the wall at an angle, the distance would be greater.

ps: I just saw your latest post, though itâ€™s still not clear how you actually raycast against your wall / point. If youâ€™re looking for the shortest distance to the plane / surface of the wall, thatâ€™s a different question. You really need to clarify what you actually want to do. You mentioned that you used a raycast for reference a couple of times. However a raycast needs a direction that you cast the ray into. So you may want to show how you actually used the raycast with proper screenshots / drawing explaining your situation. Making us speculate about your setup / problem doesnâ€™t really help