Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Clamping the spline length
#2
Hi,
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.
Reply


Messages In This Thread
Clamping the spline length - by GetUpKidAK - 09-29-2017, 01:06 AM
RE: Clamping the spline length - by _Aka_ - 01-17-2018, 10:15 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Curvy Line Renderer for UI Spline? gekido 3 6 04-04-2024, 12:56 PM
Last Post: _Aka_
  Get position of all control points for a spline gekido 1 6 03-28-2024, 10:08 PM
Last Post: _Aka_
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 14 03-04-2024, 11:06 AM
Last Post: _Aka_

Forum Jump: