BezierCurves.BezierCurve3D.GetPoint C# (CSharp) Method

GetPoint() public method

Evaluates a position along the curve at a specified normalized time [0, 1]
public GetPoint ( float time ) : Vector3
time float The normalized length at which we want to get a position [0, 1]
return UnityEngine.Vector3
        public Vector3 GetPoint(float time)
        {
            // The evaluated points is between these two points
            BezierPoint3D startPoint;
            BezierPoint3D endPoint;
            float timeRelativeToSegment;

            this.GetCubicSegment(time, out startPoint, out endPoint, out timeRelativeToSegment);

            return BezierCurve3D.GetPointOnCubicCurve(timeRelativeToSegment, startPoint, endPoint);
        }

Usage Example

Example #1
0
    private void Update()
    {
        if (goingForward && !WalkerController.walkerController.paused)
        {
            progress = WalkerController.walkerController.progress; //Global variable control
            if (progress > 1f)
            {
                if (mode == SplineWalkerMode.Once)
                {
                    progress = 1f;
                }
                else if (mode == SplineWalkerMode.Loop)
                {
                    progress -= 1f;
                }
                else
                {
                    progress     = 2f - progress;
                    goingForward = false;
                }
            }
        }
        else if (!goingForward && !WalkerController.walkerController.paused)
        {
            progress -= Time.deltaTime / duration;
            if (progress < 0f)
            {
                progress     = -progress;
                goingForward = true;
            }
        }
        else             //paused
        {
            progress = WalkerController.walkerController.progress;
        }

        Vector3 position = spline.GetPoint(progress);

        transform.localPosition = position;
        if (lookForward && !WalkerController.walkerController.paused)
        {
            transform.LookAt(spline.GetPoint(progress + Time.deltaTime));//Not actually used in our final iteration
        }
    }