Beispiel #1
0
 public Coroutine StartVelocityOverride(Rigidbody rb, Vector3 forward, VelocityOverrideData voData)
 {
     _currentChainIndex = 0;
     _currentChainData  = null;
     PinouUtils.Coroutine.RestartCoroutine(ApplyVelocityOverrideCoroutine(rb, forward, voData, true), ref _currentCoroutine);
     return(_currentCoroutine);
 }
Beispiel #2
0
 public void StopAgent()
 {
     _currentChainIndex = 0;
     _currentVoData     = null;
     _currentChainData  = null;
     PinouUtils.Coroutine.StopCoroutine(ref _currentCoroutine);
     OnAgentStop.Invoke(this);
 }
Beispiel #3
0
        private IEnumerator ExecuteDistanceOverrideCoroutine(Rigidbody rb, VelocityOverrideData voData)
        {
            Vector3 destination = Vector3.zero;

            if (voData.DirectionMode == VelocityOverrideDirectionMode.Absolute)
            {
                destination = voData.Destination;
            }
            else if (voData.DirectionMode == VelocityOverrideDirectionMode.Local)
            {
                destination = rb.position + voData.Destination;
            }

            Vector3 relativeToDestination = destination - rb.position;
            float   relativeDistance      = relativeToDestination.magnitude;
            Vector3 direction             = relativeToDestination / relativeDistance;

            float estimatedAverageSpeed = relativeDistance / voData.Duration;
            float estimatedCurveSpeed   = (1 / voData.AverageCurveValue) * estimatedAverageSpeed;

            float count = Time.fixedDeltaTime, progress;

            while (count < voData.Duration)
            {
                count   += Time.fixedDeltaTime;
                progress = count / voData.Duration;

                if (voData.FixedProgressOverTime == true)
                {
                    rb.velocity = direction * estimatedAverageSpeed * _statsSpeedFactor;
                }
                else
                {
                    rb.velocity = direction * voData.OverTimeCurve.Evaluate(progress) * estimatedCurveSpeed * _statsSpeedFactor;
                }

                yield return(new WaitForFixedUpdate());
            }
        }
Beispiel #4
0
        private IEnumerator ApplyVelocityOverrideCoroutine(Rigidbody rb, Vector3 forward, VelocityOverrideData voData, bool stopAtEnd = false)
        {
            _currentVoData = voData;
            yield return(new WaitForSeconds(voData.WaitDuration));

            if (voData.OverrideMode == VelocityOverrideMode.Speed)
            {
                yield return(ExecuteSpeedOverrideCoroutine(rb, forward, voData));
            }
            else if (voData.OverrideMode == VelocityOverrideMode.Distance)
            {
                yield return(ExecuteDistanceOverrideCoroutine(rb, voData));
            }

            if (voData.BrakeAtEnd == true)
            {
                rb.velocity = Vector3.zero;
            }

            if (stopAtEnd == true)
            {
                StopAgent();
            }
        }
Beispiel #5
0
 public VelocityOverrideChainData(VelocityOverrideData voData)
 {
     _overrideChain = new VelocityOverrideData[] { voData };
 }
Beispiel #6
0
        private IEnumerator ExecuteSpeedOverrideCoroutine(Rigidbody rb, Vector3 forward, VelocityOverrideData voData)
        {
            Vector3 right;
            Vector3 up;

            if (voData.DirectionMode == VelocityOverrideDirectionMode.Absolute)
            {
                forward = Vector3.forward;
                right   = Vector3.right;
                up      = Vector3.up;
            }
            else
            {
                Quaternion rotation = Quaternion.LookRotation(forward, Vector3.up);
                up    = PinouUtils.Transform.TransformVector(Vector3.up, rotation);
                right = Vector3.Cross(forward, up);
            }

            Vector3 direction = (forward * voData.Direction.z + right * voData.Direction.x + up * voData.Direction.y).normalized;


            float count = 0f, progress;

            while (count < voData.Duration)
            {
                count   += Time.fixedDeltaTime;
                progress = count / voData.Duration;

                if (voData.FixedProgressOverTime == true)
                {
                    rb.velocity = direction * voData.SpeedFactor * _statsSpeedFactor;
                }
                else
                {
                    rb.velocity = direction * voData.OverTimeCurve.Evaluate(progress) * voData.SpeedFactor * _statsSpeedFactor;
                }

                yield return(new WaitForFixedUpdate());
            }
        }