Do you want to find the point on the z axis that is

- closest to a specific point on the spline
**or** - closest to
*all*points on the spline

Do you want to find the point on the z axis that is

- closest to a specific point on the spline
**or** - closest to
*all*points on the spline

1 Like

Iâ€™m trying to do something similar to FindLocationClosestToWorldLocation, but instead of finding the closest point in 3D space, I want to find the closest point along the Z axis. Is there some way to accomplish this or would I have to extend USplineComponent somehow?

Speaking of which, can you extend UObjects like USplineComponent without building from source?

No its more like this in the picture:

The black point is my location in the world. The red line would be what FindLocationClosestToWorldLocation would do, but I want the blue line, the closest location on the z axis (which may or may not exist of course depending on the spline).

Edit: Just another rudimentary example to show what I mean in 3D:

So the red line might be the closest point on the spline to my location, but the blue line is the closest point along an axis, in this case I made it the y axis. Or really I should say, Iâ€™m taking the YZ plane cutout from my location, and finding the closest point in the spline that intersects with the plane.

I donâ€™t see better way than iterate on all points of your splineâ€¦

Then you use the function GetPointDistancetoLine and choose the best result.

With:

- Point: the point on your spline
- Line: Your axis

I looked into the source code but unfortunately the algorithm used to find the closest point on a spline to a location is beyond my mathematical skills. But I saw that they used an â€śinaccurateâ€ť algorithm, i.e. they try to get closer to the nearest point by iterating. So I would do the same as suggested by 42EspoiR, iterating over a certain amount of points with a predefined delta distance between them, but use FVector::PointPlaneDist instead.

Yea I just looked at that as well. I think I can just do something similar to what they did within my own code, since I can just use GetSplinePointsPosition to get the FInterpCurveVector and then go from there and use my own version of InaccurateFindNearest for planes.

Thanks! 2024 and this solution is still rocking. Wondering if it is still the best / only one out there?