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_fl...69c49bc5a6

Let me know if you have any other questions
Have a nice day
Please consider leaving a review for Curvy, this helps immensely. Thank you.
Available for freelance work—feel free to reach out.
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_fl...2887988f39
Please consider leaving a review for Curvy, this helps immensely. Thank you.
Available for freelance work—feel free to reach out.
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
  Disable a spline's gizmo when not selected or disabled. mikechr2000 1 140 02-03-2025, 09:34 AM
Last Post: _Aka_
Information Questions regarding spline colliders and collisions with rigidbodies Spyboticer 7 510 01-20-2025, 12:25 PM
Last Post: _Aka_
  Extrude mesh along spline. New and confused user GhostStalker 3 214 01-02-2025, 09:58 AM
Last Post: _Aka_
  Newly created spline is invisible quickytools 7 497 12-21-2024, 10:14 AM
Last Post: _Aka_

Forum Jump: