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 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_fl...2887988f39
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
  Syncing UI Spline and Regular 3D Spline arrnav96 8 84 03-21-2019, 12:13 PM
Last Post: _Aka_
  Rotation issue on a Parented Spline Controller Karthik7Nike 6 694 12-07-2018, 09:35 AM
Last Post: _Aka_
  Generated meshes not 'parallel' to spline Alexey 8 1,019 11-20-2018, 07:13 PM
Last Post: Alexey
  Freewalk mode, then return to spline mythstified 6 1,635 11-09-2018, 08:20 AM
Last Post: sanaeerumey

Forum Jump: