01-17-2018, 10:15 PM
Hi,
Here is a method I quickly coded that does what you want. It surely can be enhanced:
Here is a method I quickly coded that does what you want. It surely can be enhanced:
Code:
private static bool RemoveExcess(CurvySpline spline, Vector3 terminatorWorldPosition)
{
if (spline.IsInitialized == false)
return false;
//The position at which the spline should stop
Vector3 nearestSplinePointToTerminator;
float terminatorTf = spline.GetNearestPointTF(terminatorWorldPosition, out nearestSplinePointToTerminator);
//The index of the last segment to keep, all following segements are removed
int terminatorSegmentIndex = spline.TFToSegmentIndex(terminatorTf);
//remove all control points beyong the terminator
int segmentsCount = spline.Count;
for (int segmentIndex = segmentsCount - 1; segmentIndex >= terminatorSegmentIndex; segmentIndex--)
spline.Delete(spline.Segments[segmentIndex].NextControlPoint);
//Add the last control point
spline.Add(nearestSplinePointToTerminator);
return true;
}
Please consider leaving a review for Curvy. This will help a lot keeping Curvy relevant in the eyes of the Asset Store algorithm.