Example #1
0
 public static EagleSettings Lerp(EagleSettings es1, EagleSettings es2, float t)
 {
     return(new EagleSettings()
     {
         FrameSet = EagleAnim.FrameSet.Lerp(es1.FrameSet, es2.FrameSet, t),
         Angle = Mathf.Lerp(es1.Angle, es2.Angle, t),
         FpsScale = Mathf.Lerp(es1.FpsScale, es2.FpsScale, t),
         animLoopType = t > 0.5 ? es2.animLoopType : es1.animLoopType
     });
 }
Example #2
0
        private void Update()
        {
            // get input
            var input = new Vector2(
                Input.GetAxis("Horizontal"),
                Input.GetAxis("Vertical")
                );

            // map square input to circle, to maintain uniform speed in all directions
            _inputCircular = new Vector2(
                input.x * Mathf.Sqrt(1 - input.y * input.y * 0.5f),
                input.y * Mathf.Sqrt(1 - input.x * input.x * 0.5f)
                );

            EagleAnim.FrameSet     currentFrameSet;
            EagleAnim.AnimLoopType currentAnimLoopType = EagleAnim.AnimLoopType.PingPong;
            float currentFpsScale;
            float currentAngle = 0;

            EagleSettings currentSettings = Settings_Y_0_X_0;
            float         tx = _inputCircular.x;
            float         ty = _inputCircular.y;

            // split it into quadrants
            //    |    2    |    1    |
            //    |_________|_________|
            //    |         |         |
            //    |    3    |    4    |
            float t;

            if (tx > 0)
            {
                if (ty > 0)
                { // 1
                    t = Vector2.Angle(Vector2.right, _inputCircular) / 90f;
                    currentSettings = EagleSettings.Lerp(Settings_X_POS1, Settings_Y_POS1, t);
                }
                else
                { // 4
                    t = Vector2.Angle(Vector2.down, _inputCircular) / 90f;
                    currentSettings = EagleSettings.Lerp(Settings_Y_NEG1, Settings_X_POS1, t);
                }
            }
            else
            {
                if (ty > 0)
                { // 2
                    t = Vector2.Angle(Vector2.up, _inputCircular) / 90f;
                    currentSettings = EagleSettings.Lerp(Settings_Y_POS1, Settings_X_NEG1, t);
                }
                else
                { // 3
                    t = Vector2.Angle(Vector2.left, _inputCircular) / 90f;
                    currentSettings = EagleSettings.Lerp(Settings_X_NEG1, Settings_Y_NEG1, t);
                }
            }

            currentSettings = EagleSettings.Lerp(Settings_Y_0_X_0, currentSettings, _inputCircular.magnitude);

//            // lerp on x first, then on Y, but in practise it doesn't matter
//            if (input.x < 0)
//            {
//                currentFrameSet = EagleAnim.FrameSet.Lerp(Settings_Y_0_X_0.FrameSet, Settings_X_NEG1.FrameSet, tx);
//                currentFpsScale = Mathf.Lerp(Settings_Y_0_X_0.FpsScale, Settings_X_NEG1.FpsScale,tx);
//                currentAngle = Mathf.Lerp(Settings_Y_0_X_0.Angle, Settings_X_NEG1.Angle, tx);
//            }
//            else
//            {
//                currentFrameSet = EagleAnim.FrameSet.Lerp(Settings_Y_0_X_0.FrameSet, Settings_X_POS1.FrameSet, tx);
//                currentFpsScale = Mathf.Lerp(Settings_Y_0_X_0.FpsScale, Settings_X_POS1.FpsScale,tx);
//                currentAngle = Mathf.Lerp(Settings_Y_0_X_0.Angle, Settings_X_POS1.Angle, tx);
//            }
//            if (input.y < 0)
//            {
//                currentFrameSet = EagleAnim.FrameSet.Lerp(currentFrameSet, Settings_Y_NEG1.FrameSet, ty);
//                currentFpsScale = Mathf.Lerp(currentFpsScale, Settings_Y_NEG1.FpsScale,ty);
//                currentAngle = Mathf.Lerp(currentAngle, Settings_Y_NEG1.Angle, ty);
//                //currentAnimLoopType = Settings_Y_NEG1.animLoopType;
//            }
//            else
//            {
//                currentFrameSet = EagleAnim.FrameSet.Lerp(currentFrameSet, Settings_Y_POS1.FrameSet, ty);
//                currentFpsScale = Mathf.Lerp(currentFpsScale, Settings_Y_POS1.FpsScale,ty);
//                currentAngle = Mathf.Lerp(currentAngle, Settings_Y_POS1.Angle, ty);
//                //currentAnimLoopType = Settings_Y_POS1.animLoopType;
//            }

            _eagleAnim.SetFrameSet(currentSettings.FrameSet);
            _eagleAnim.SetAnimType(currentSettings.animLoopType);
            _eagleAnim.SetFpsScale(currentSettings.FpsScale);
            _eagleMovement.LerpMovementSpeed(_inputCircular);
            transform.rotation = Quaternion.Euler(0, 0, currentSettings.Angle);
        }