Beispiel #1
0
        /**
         *<summary>
         * Calculates an interpolation value and returns the interpolated point along a Catmull-Rom spline defined by four points
         *</summary>
         */
        Vector3 findNextPlaceOnPath()
        {
            interpolator += Time.deltaTime * heuristicIteratorIncrement;

            //Ensures a that interpolating b/w two points starts at 0
            if (didPathingResetLastFrame)
            {
                interpolator             = 0;
                didPathingResetLastFrame = false;
            }

            //Ensures a that interpolating b/w two points ends at 1
            if (interpolator >= 1)
            {
                interpolator = 1;
            }

            //Calculate the position along the spline
            Vector2 nextPos = CatmullRom.returnCatmullRom(interpolator, pathKeyPoints[index0], pathKeyPoints[index1], pathKeyPoints[index2], pathKeyPoints[index3]);

            //Update the pathing indices when interpolator finishes a 0-1 cycle
            if (interpolator >= 1)
            {
                incrementPathingIndex();
            }

            return(new Vector3(nextPos.x, yOffset, nextPos.y));
        }