Beispiel #1
0
        /// <summary>
        /// Simple cosinuosidal animation during transitioning to new target
        /// </summary>
        private void NoddingCalculations()
        {
            if (nodProgress < nodDuration)
            {
                if (nodProgress < nodDuration)
                {
                    nodProgress += delta;
                }
                else
                {
                    nodProgress = nodDuration;
                }

                float progress = nodProgress / nodDuration;
                progress = FEasing.EaseOutCubic(0f, 1f, progress);

                if (progress >= 1f)
                {
                    nodValue = 0f;
                }
                else
                {
                    nodValue = Mathf.Sin(progress * (Mathf.PI));
                }
            }
        }
        /// <summary>
        /// Calculating sustain feature offset
        /// </summary>
        void Waving_SustainUpdate()
        {
            TailSegment firstB = TailSegments[0];

            // When tail is short and have few segments we have to ampify sustain effect behaviour and vice versa
            float tailRatio = (_TC_TailLength / (float)TailSegments.Count);

            tailRatio = Mathf.Pow(tailRatio, 1.65f);
            tailRatio = (_sg_curly / tailRatio) / 6f;

            // Clamp extreme values
            if (tailRatio < 0.1f)
            {
                tailRatio = 0.1f;
            }
            else if (tailRatio > 1f)
            {
                tailRatio = 1f;
            }

            int mid = (int)Mathf.LerpUnclamped(TailSegments.Count * 0.4f, TailSegments.Count * 0.6f, Sustain);

            float susFact = FEasing.EaseOutExpo(1f, 0.09f, Sustain);

            float mild = 1.5f;

            mild *= (1f - TailSegments[0].Curling / 8f);
            mild *= (1.5f - tailRatio / 1.65f);
            mild *= Mathf.Lerp(0.7f, 1.2f, firstB.Slithery);
            mild *= FEasing.EaseOutExpo(1f, susFact, firstB.Springiness);

            Vector3 velo = TailSegments[mid].PreviousPush;

            if (mid + 1 < TailSegments.Count)
            {
                velo += TailSegments[mid + 1].PreviousPush;
            }
            if (mid - 1 > TailSegments.Count)
            {
                velo += TailSegments[mid - 1].PreviousPush;
            }


            _waving_sustain = velo * Sustain * mild * 2f;

            #region Backup
            //_waving_sustain = Vector3.Lerp(_waving_sustain, TailBones[mid].PreviousPush * Sustain * mild, unifiedDelta);
            //Vector3.SmoothDamp
            //(
            //_waving_sustain,
            //TailBones[mid].PreviousPush * Sustain * mild,
            //ref _waving_sustainVelo,
            //Mathf.LerpUnclamped(0.15f + tailRatio / 5f, 0.1f + tailRatio / 5f, Sustain),
            //Mathf.Infinity, Time.smoothDeltaTime);

            //TailBones[Mathf.Min(TailBones.Count - 1, _tc_startII)].PreviousPosition += _waving_sustain * mild;
            #endregion
        }
        /// <summary>
        /// Refreshing reference pose for animation
        /// </summary>
        private IEnumerator CRefreshReferencePose()
        {
            // Wait for animation transition in animator and then remembering pose
            yield return(null);

            yield return(new WaitForSecondsRealtime(0.05f));

            // Preparing variables to proceed transition
            if (_monitorTransitionStart == null)
            {
                _monitorTransitionStart = new List <Quaternion>();
            }


            if (_monitorTransitionStart.Count != LookBones.Count)
            {
                for (int i = 0; i < LookBones.Count; i++)
                {
                    _monitorTransitionStart.Add(LookBones[i].animatedStaticRotation);
                }
            }

            for (int i = 0; i < LookBones.Count; i++)
            {
                LookBones[i].RefreshStaticRotation(false);
            }

            // Doing transition
            float elapsed = 0f;

            while (elapsed < monitorTransitionTime)
            {
                elapsed += delta;
                float progress = FEasing.EaseInOutCubic(0f, 1f, elapsed / monitorTransitionTime);

                for (int i = 0; i < LookBones.Count; i++)
                {
                    LookBones[i].animatedStaticRotation = Quaternion.Slerp(_monitorTransitionStart[i], LookBones[i].targetStaticRotation, progress);
                }

                yield return(null);
            }

            // Finishing
            for (int i = 0; i < LookBones.Count; i++)
            {
                LookBones[i].animatedStaticRotation = LookBones[i].targetStaticRotation;
            }

            yield break;
        }
Beispiel #4
0
        /// <summary>
        /// Computing elastic clamp angle for given parameters
        /// </summary>
        private float GetClampedAngle(float current, float limit, float elastic, float sign = 1f)
        {
            if (elastic <= 0f)
            {
                return(limit);
            }
            else
            {
                float elasticRange = 0f;

                if (elastic > 0f)
                {
                    elasticRange = FEasing.EaseOutCubic(0f, elastic, (current * sign - limit * sign) / (180f + limit * sign));
                }

                return(limit + elasticRange * sign);
            }
        }
Beispiel #5
0
 /// <summary>
 /// Moves target object back to initial position and rotation
 /// </summary>
 public void MoveBack()
 {
     goToTarget = false;
     enabled    = true;
     func       = FEasing.GetEasingFunction(EaseFunction);
 }
        /// <summary>
        /// Sometimes courutine is better than Update() because update is running during whole time
        /// but courutine can be used only when is needed,
        /// notice that about 1000 behaviours with empty Update() can do some overload on CPU
        /// </summary>
        IEnumerator ClickAniamtion()
        {
            buttonTransform.localPosition = buttonInitPosition;
            float time = 0f;

            while (time < AnimationTime * 0.6f)
            {
                time += Time.deltaTime;

                float progress = time / AnimationTime;

                buttonTransform.localPosition = Vector3.LerpUnclamped(buttonInitPosition, buttonInitPosition - Vector3.up * 0.05f, FEasing.EaseOutElastic(0f, 1f, progress, EaseExtraValue));

                yield return(null);
            }

            time = 0f;

            Vector3 currentPos = buttonTransform.localPosition;

            while (time < AnimationTime / 4f)
            {
                time += Time.deltaTime;

                float progress = time / (AnimationTime / 4f);

                buttonTransform.localPosition = Vector3.LerpUnclamped(currentPos, buttonInitPosition, FEasing.EaseInOutCubic(0f, 1f, progress));

                yield return(null);
            }

            yield break;
        }