Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How do I find closest spline ?
#1
So I have a list of splines & I want to find the closest one (not necessarily the one with the closest control point)

Hi so how could I find the closest spline to a world position.








Thanks.
Reply
#2
Hi,

You will have to go through all the splines, compute the distance from your point for each one of them, and then selecting the spline with the shortest distance.
To compute that distance, you will have to use the CurvySpline.GetNearestPointTF(Vector3 localPosition, out Vector3 nearest).
Here is its documentation: https://api.curvyeditor.com/520/class_fluffy_underware_1_1_curvy_1_1_curvy_spline.html#a826c07a945b2ddc06e627369c49bc5a6

Let me know if you have any other questions
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.
Reply
#3
Hi thanks.
Ok so I understand that the TF value is a point along the spline, I'm not sure how I can calculate the distance with that. Is it possible to get a position vector in world space from a TF value ?
Reply
#4
In the method I linked to you, the second parameter, which is an out parameter, is the nearest point on the spline, in its local coordinates. Then use Unity's Transform.TransformPoint to transform the point to global coordinates.

About getting a point from a TF value, you can do that using CurvySpline.Interpolate(float tf) to transform a TF to a Vector3, in the local coordinates system of the spline.
Here is its documentation: https://api.curvyeditor.com/520/class_fluffy_underware_1_1_curvy_1_1_curvy_spline.html#a5a2733111f8c35a6be80b42887988f39
Please consider leaving a review for Curvy. This will help a lot keeping Curvy relevant in the eyes of the Asset Store algorithm.
Reply
#5
Nice one thanks, I didn't need the TF value in the end just the local position.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
Bug Changing spline connection in inspector causes splines to revert to defaults lacota 3 6 03-18-2024, 07:55 PM
Last Post: _Aka_
  GO can't fit end of the spline GameDeveloperek4123 3 13 03-04-2024, 11:06 AM
Last Post: _Aka_
  Keeping a fixed spline length jh092 3 16 02-21-2024, 06:25 AM
Last Post: Primrose44
  How could I get position in spline from "From" value in BuildRasterizedPath? Chanon 1 8 02-12-2024, 09:54 PM
Last Post: _Aka_

Forum Jump: