I might be bad at explaining what exactly I'm looking to do but,

I'm looking for a way to get a position above(as in Y axis) a spline that has been drawn on XZ axis.

Easiest way to describe it might be to have the ray stop as it reaches the XZ coordinates along the spline and wish to get the world position straight above the spline at the cross-section.

Currently I'm using ScreenPointToRay to get the position when clicking, but I'm not sure on what would be the best method for what I'm looking to do.

I have thought of just looking through the clicked ray that is being cast and using the GetNearestPoint to get the other comparable point, then look for position when the angle from the spline point to the ray is 0, but this method might have various issues if I'm using too curvy splines and the nearest point isn't "below" the clicked point.

The fact I'm looking it to be above is somewhat irrelevant, as I just want the coordinates relative to the click, but due to colliders I believe there will not be a case where the ray from mouse click would hit the location below the spline before hitting anything else.

07-11-2023, 09:30 AM (This post was last modified: 07-11-2023, 09:31 AM by _Aka_.)

Hi

There is no ready out of the box solution for this issue in Curvy Splines. You will have to code something. Here is what seems to me like a good logic to implement:
Simplify the problem by restricting it to the XZ plane (this means you will have to project the ray on that plane). Then find the nearest point on the spline from that ray. Then finally restore the Y coordinate to get the point on the real XYZ ray.

About finding the nearest point from the spline to the ray. There might be an optimized way to do it that I am not aware of, but an easy way would be to test multiple points on the ray and compute their distance from the spline. To do so use GetNearestPoint and compute the distance between the result point an the ray point. To reduce the number of points tested, if their high number is an issue, you can use some optimization strategy such as Binary Search.

I hope this helped
Have a nice day

Please consider leaving a review for Curvy. This will help a lot keeping Curvy relevant in the eyes of the Asset Store algorithm.

There is no ready out of the box solution for this issue in Curvy Splines. You will have to code something. Here is what seems to me like a good logic to implement:
Simplify the problem by restricting it to the XZ plane (this means you will have to project the ray on that plane). Then find the nearest point on the spline from that ray. Then finally restore the Y coordinate to get the point on the real XYZ ray.

About finding the nearest point from the spline to the ray. There might be an optimized way to do it that I am not aware of, but an easy way would be to test multiple points on the ray and compute their distance from the spline. To do so use GetNearestPoint and compute the distance between the result point an the ray point. To reduce the number of points tested, if their high number is an issue, you can use some optimization strategy such as Binary Search.

I hope this helped
Have a nice day

Thank you for the quick answer, but after few tests I'm not sure if I got the hang of it.

Currently the fact that the hit location for the ray and the curviness of the spline cause some misalignment with the closest point.

Here's a more comprehensive image about the situation

I had a thought of using the "player"- or camera position as and offset of sorts to somehow get the correct location, but I don't think it would scale correctly when used on more straight splines.

Hi
Here is the implementation of a GetNearestPointTF. Just add these two files to ToolBuddy\Assets\Curvy\Scripts\Splines
With this, you should be able to find the nearset point on a spline to a ray.

Please consider leaving a review for Curvy. This will help a lot keeping Curvy relevant in the eyes of the Asset Store algorithm.

And here is a zip with test scene and script. The two cubes define a ray's origin and direction, and the red cross is the nearest point. The script runs in playmode.

Please consider leaving a review for Curvy. This will help a lot keeping Curvy relevant in the eyes of the Asset Store algorithm.