コード例 #1
0
        public void Roll(RollDir dir)
        {
            //如果正在翻滚就不能在翻滚了
            if (rolling || dodgeing)
            {
                return;
            }

            rolling     = true;
            usingMotion = true;
            //翻滚的时候使用apply motion
            role.monoReference.animator.applyRootMotion = true;
            switch (dir)
            {
            case RollDir.Forward:
                role.animComponent.animator.CrossFade(m_AnimName.roll_Forward, 0.15f, 0, 0);
                break;

            case RollDir.Backward:
                role.animComponent.animator.CrossFade(m_AnimName.roll_Backward, 0.15f, 0, 0);
                break;

            case RollDir.Left:
                role.animComponent.animator.CrossFade(m_AnimName.roll_Left, 0.15f, 0, 0);
                break;

            case RollDir.Right:
                role.animComponent.animator.CrossFade(m_AnimName.roll_Right, 0.15f, 0, 0);
                break;
            }
        }
コード例 #2
0
ファイル: Ship.cs プロジェクト: Thinny-Hendrix/MoonCow
        void updateBarrelRoll()
        {
            if (!game.camera.endGame && !game.minigame.active)
            {
                if ((Keyboard.GetState().IsKeyDown(Keys.Q) || GamePad.GetState(PlayerIndex.One).ThumbSticks.Right.X < -0.3f) && rollCooldown <= 0)
                {
                    rollCooldown = 30;
                    rollRecoverTime = MathHelper.PiOver2;

                    if (roll < 0 && rollState == RollState.rolling)
                        targetRoll = 0;
                    else
                        targetRoll = MathHelper.Pi * 2;

                    rollState = RollState.rolling;
                    rollDir = RollDir.left;

                }

                if ((Keyboard.GetState().IsKeyDown(Keys.E) || GamePad.GetState(PlayerIndex.One).ThumbSticks.Right.X > 0.3f) && rollCooldown <= 0)
                {
                    rollCooldown = 30;
                    rollRecoverTime = MathHelper.PiOver2;

                    if (roll > 0 && rollState == RollState.rolling)
                        targetRoll = 0;
                    else
                        targetRoll = -MathHelper.Pi * 2;

                    rollState = RollState.rolling;
                    rollDir = RollDir.right;

                }
            }

            if (rollState == RollState.rolling) //todo - treat sideways movement like forwards with lerping
            {
                if (rollCooldown > 0)
                    rollCooldown -= 60 * Utilities.deltaTime;

                if (rollDir == RollDir.left)
                {
                    sideSpeed = MathHelper.Lerp(sideSpeed, 15, Utilities.deltaTime*5);
                    roll += MathHelper.Pi * Utilities.deltaTime * 4 * (sideSpeed/15);

                    if (roll > targetRoll)// && rollCooldown >= 10)
                    {
                        rollCooldown = 0;
                        roll = 0;
                        rollState = RollState.recovering;

                    }
                }
                else
                {
                    sideSpeed = MathHelper.Lerp(sideSpeed, -15, Utilities.deltaTime * 5);
                    roll += MathHelper.Pi * Utilities.deltaTime * 4 * (sideSpeed / 15);

                    if (roll < targetRoll)// && rollCooldown >= 10)
                    {
                        rollCooldown = 0;
                        roll = 0;
                        rollState = RollState.recovering;
                    }
                }
            }
            else
            {
                sideSpeed = MathHelper.Lerp(sideSpeed, 0, Utilities.deltaTime * 8);
            }
            if(rollState == RollState.recovering)
            {
                if(rollDir == RollDir.left)
                    roll = (float)((Math.Cos(rollRecoverTime) - 1) * 0.5f) * -MathHelper.Pi * Utilities.deltaTime * 8;
                if (rollDir == RollDir.right)
                    roll = (float)((Math.Cos(rollRecoverTime) - 1) * 0.5f) * MathHelper.Pi * Utilities.deltaTime * 8;

                //                    roll = (float)((Math.Cos(rollRecoverTime) - 1) * 0.5f) * MathHelper.PiOver4*0.65f;

                rollRecoverTime += MathHelper.Pi * 3.5f * Utilities.deltaTime;
                if(rollRecoverTime >= MathHelper.Pi*2)
                {
                    rollState = RollState.not;
                    roll = 0;
                    rollRecoverTime = MathHelper.PiOver2;
                }

            }

            frameDiff.X += Vector3.Cross(Vector3.Up, direction).X * sideSpeed * Utilities.deltaTime;
            frameDiff.Z += Vector3.Cross(Vector3.Up, direction).Z * sideSpeed * Utilities.deltaTime;
            rot.Z += roll;
        }