Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Dynamic path
#1
I am trying to use Curvy as a way-point system.
I need to make a path between my object and a target point. I dynamically create a new CurvySpline with those two points transforms. Is there a way to pass initial object rotation to make it a curved route , not a straight line without too much calculations?

public SplineWalkerDistance _splineWalker;

_splineWalker.Spline = CreateSpline();

 CurvySpline CreateSpline()
{
        if ( Vector3.SqrMagnitude( _target.position - transform.position ) < 1f)
            return null;

        CurvySpline spline = CurvySpline.Create();
        spline.SetControlPointRotation = true;
        spline.Closed = false;
        spline.InitialUpVector = CurvyInitialUpDefinition.ControlPoint;
        spline.AutoEndTangents = true;
        spline.Granularity = 10;
        spline.AutoRefresh = true;
        spline.AutoRefreshLength = true;
        spline.AutoRefreshOrientation = true;
        spline.ShowApproximation = true;

        Vector3[] vec = new Vector3[2];
        vec[0] = transform.position;
        vec[1] = _target.position;
        spline.Add(vec);

        return spline;
}


 

 

 
Reply
#2
(01-24-2014, 12:08 AM)'savely00' Wrote: Is there a way to pass initial object rotation to make it a curved route , not a straight line without too much calculations?

 

You can set CP rotation easily by altering a CP's transform (access it using mySpline.ControlPoints[x]), but that would only change orientation (=the Up-Vector) of the spline, not the curve itself.
Having a spline with just two CPs will result in a straight line, no matter what. You'll need to tell the spline more about the curvation you want:
  • Let AutoEndTangents enabled and add a CP in the middle that the curve will go through automatically
  • disable AutoEndTangents and use 4 CPs. Set CP 1+2 to your start and end position and use CP 0 and CP 3 to define the curvation
  • Use 2 CPs like now but set Interpolation to Bezier and alter the Handles to define the curve
I guess the first solution would be the easiest calculation wise while the other two gives you total control. What about having 3 CPs with CP0: a previous position of the object, CP1: current position, CP2: target position and starting at TF 0.333 or CurvySpline.SegmentToTF().

Jake
Reply
#3
Thank you Jake.

For now I went with the first solution but later I'll play with the other suggestions as well.

-Savely
Reply


Possibly Related Threads...
Thread Author Replies Views Last Post
  Extrude custom mesh along a path CesarGenera 3 479 09-19-2019, 04:47 PM
Last Post: _Aka_
  Path not as smooth as spline jawadkhan.9026 3 931 06-12-2019, 11:19 AM
Last Post: _Aka_
  How can I make the path visible in game? PretzelStudios 4 994 06-02-2019, 09:01 PM
Last Post: _Aka_
  Find if object is on spline path nciofi 1 1,589 07-10-2018, 09:23 AM
Last Post: _Aka_

Forum Jump: