Evaluate() public abstract method

public abstract Evaluate ( float t, Vector3 &tangent, Vector3 &curvature ) : Vector3
t float
tangent UnityEngine.Vector3
curvature UnityEngine.Vector3
return UnityEngine.Vector3
Beispiel #1
0
        protected static Vector3[] GetCurvePositions(Curve curve, int resolution, Vector3[] controlPoints)
        {
            var pointsOnCurve = new Vector3[resolution + 1];

            pointsOnCurve[0] = controlPoints[0];
            var tangent   = Vector3.zero;
            var curvature = Vector3.zero;

            for (var j = 1; j <= resolution; j++)
            {
                var t = 1f / resolution * j;
                pointsOnCurve[j] = curve.Evaluate(t, out tangent, out curvature);
            }
            return(pointsOnCurve);
        }
Beispiel #2
0
 protected static Vector3[] GetCurvePositions(Curve curve, int resolution, Vector3[] controlPoints)
 {
     var pointsOnCurve = new Vector3[resolution + 1];
     pointsOnCurve[0] = controlPoints[0];
     var tangent = Vector3.zero;
     var curvature = Vector3.zero;
     for (var j = 1; j <= resolution; j++)
     {
         var t = 1f / resolution * j;
         pointsOnCurve[j] = curve.Evaluate(t, out tangent, out curvature);
     }
     return pointsOnCurve;
 }
Beispiel #3
0
        public void MoveAlongCurve(float time, float speed, out Vector3 position, out Quaternion rotation)
        {
            position = _prevPosition;
            rotation = _prevRotation;

            if (Curve == null)
            {
                Debug.LogError("No assigned Path to follow!");
                return;
            }

            _positionAlongCurve += speed * (time - _prevTime); // alows for variable speed but involves deltas (cant be determined at a time with a single call)
            var linearTime = GetLinearTimeOnCurve(_positionAlongCurve);

            if (linearTime >= 1f)
            {
                Evt_ReachedEnd(_prevTime + (_positionAlongCurve - Curve.Length) / speed); // send up time at which end was reached
                return;
            }

            // Update pos
            Vector3 tangent;
            Vector3 curvature;

            position = Curve.Evaluate(linearTime, out tangent, out curvature);

            float bankAngle = 0f;

            if (_maxBankAngle > 0 && _bankSmoothing > 0f)
            {
                // Compute Bank
                var targetBankAngle = Curve.GetBankAngle(tangent, curvature, _maxBankAngle);
                bankAngle      = Mathf.Lerp(_prevBankAngle, targetBankAngle, Time.deltaTime / _bankSmoothing);
                _prevBankAngle = bankAngle;
            }

            if (_maxDrift > 0 && speed > 0)
            {
                // Compute Drift
                var futurePosOnCurveDist = _positionAlongCurve + (speed * _maxDrift);
                futurePosOnCurveDist = Mathf.Clamp(futurePosOnCurveDist, 0f, Curve.Length);
                var futurePosOnCurve = Curve.Evaluate(GetLinearTimeOnCurve(futurePosOnCurveDist), out tangent, out curvature);

                Debug.DrawLine(position, futurePosOnCurve);
                rotation = Quaternion.LookRotation((futurePosOnCurve - position).normalized);
            }
            else if (tangent.normalized != Vector3.zero)
            {
                rotation = Quaternion.LookRotation(tangent.normalized);
            }

            if (bankAngle != 0)
            {
                rotation *= Quaternion.AngleAxis(bankAngle, Vector3.forward);
            }

            Debug.Log(Vector3.Distance(_prevPosition, position));
            _prevPosition = position;
            _prevRotation = rotation;
            _prevTime     = time;
        }