Ejemplo n.º 1
0
        /// <summary>
        /// Returns a facing vector at the given percentage along the spline to allow content to properly orient along the spline.
        /// </summary>
        public Vector3 GetDirection(float percentage, bool normalized = true)
        {
            if (normalized)
            {
                percentage = Reparam(percentage);
            }

            //get direction:
            CurveDetail curveDetail = GetCurve(percentage);

            //avoid an error in editor usage where this index can be -1:
            if (curveDetail.currentCurve < 0)
            {
                return(Vector3.zero);
            }

            SplineAnchor startAnchor = Anchors[curveDetail.currentCurve];
            SplineAnchor endAnchor   = Anchors[curveDetail.currentCurve + 1];

            return(BezierCurves.GetFirstDerivative(startAnchor.Anchor.position, endAnchor.Anchor.position, startAnchor.OutTangent.position, endAnchor.InTangent.position, curveDetail.currentCurvePercentage).normalized);
        }