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?
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 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.