Example #1
0
 public static void DrawCurveSegments(CurveSegment curve,
                                      Color color, int segments = 50)
 {
     // DONE exercise 2.2
     // evaluate the curve from start to end (range [0, 1])
     // and you draw a number of line segments between
     // consecutive points
     for (float i = 0; i < segments; i++)
     {
         Debug.DrawLine(curve.Evaluate(i / segments), curve.Evaluate((i + 1) / segments), color);
     }
 }
Example #2
0
 public static void DrawTangents(CurveSegment curve,
                                 Color color, int segments = 50, float scale = 0.1f)
 {
     // DONE exercise 2.2
     // evaluate the curve and tangent from start to end (range [0, 1])
     // and draw the tangent as a line from the current curve point
     // to the current point + the tangent vector
     for (float i = 0; i < segments; i++)
     {
         Vector4 p = curve.Evaluate(i / segments);
         Debug.DrawLine(p, p + curve.EvaluateDv(i / segments) * scale, color);
     }
 }
Example #3
0
        void Update()
        {
            if (!curve.Init())
            {
                return;
            }

            t += Time.deltaTime / duration;
            t %= 1;

            float easedT = EasingFunctions.Linear(t); // you can use any easing function here

            float        arcLength;
            CurveSegment curveSegment = curve.CurveSegmentAtArcLength(easedT * curve.ArcLength(curve.CurveCount()), out arcLength);
            float        curveT       = curveSegment.ComputeTAtArcLength(arcLength);

            transform.position = curveSegment.Evaluate(curveT);
            transform.forward  = curveSegment.EvaluateDv(curveT);
        }