Exemple #1
0
        // Looks at DesiredMovementState and movement values and conveys the appropiate state to the animation controller.
        // Also commits the Controller movement and orientation input values.
        private void PreAnimationUpdateHandler(object sender, UpdateStepEventArgs e)
        {
            CommitOrientationAndMovement();

            if (mState != ControllerState.InputDisabled)
            {
                if (mAnimationStateMachine != null)
                {
                    if (Controller.SupportFinder.HasSupport)
                    {
                        Vector2 horizontalMovement = BepuConverter.Convert(Controller.HorizontalMotionConstraint.MovementDirection)
                                                     * Controller.HorizontalMotionConstraint.SpeedScale;

                        if ((DesiredMovementActions & MovementActions.Jumping) > 0)
                        {
                            mAnimationStateMachine.DesiredStateName = JUMPING_SN;
                        }
                        else if (DesiredMovementActions.HasFlag(MovementActions.Boosting) &&
                                 mState == ControllerState.Neutral &&
                                 mBooster != null &&
                                 mBooster.BoostReady)
                        {
                            mAnimationStateMachine.DesiredStateName = BOOSTING_SN;
                        }
                        else if ((DesiredMovementActions & MovementActions.Crouching) > 0)
                        {
                            if (horizontalMovement.LengthSquared() > 0.0f)
                            {
                                mAnimationStateMachine.HorizontalMovement = horizontalMovement;
                                mAnimationStateMachine.DesiredStateName   = CROUCHMOVING_SN;
                            }
                            else
                            {
                                mAnimationStateMachine.DesiredStateName = CROUCHING_SN;
                            }
                        }
                        else if (horizontalMovement.LengthSquared() > 0.0f)
                        {
                            mAnimationStateMachine.HorizontalMovement = horizontalMovement;
                            mAnimationStateMachine.DesiredStateName   = MOVING_SN;
                        }
                        else
                        {
                            mAnimationStateMachine.DesiredStateName = STANDING_SN;
                        }
                    }
                    else
                    {
                        mAnimationStateMachine.DesiredStateName = FALLING_SN;
                    }
                }
            }
        }
Exemple #2
0
        // Checks the animation state for control events and passes them on to the Controller.
        private void PostAnimationUpdateHandler(object sender, UpdateStepEventArgs e)
        {
            if (mAnimationStateMachine != null)
            {
                if (mAnimationStateMachine.CurrentState.Name == CROUCHING_SN ||
                    mAnimationStateMachine.CurrentState.Name == CROUCHMOVING_SN)
                {
                    Controller.StanceManager.DesiredStance = Stance.Crouching;
                }
                else
                {
                    Controller.StanceManager.DesiredStance = Stance.Standing;
                }

                if (mAnimationStateMachine.ActiveControlEvents.HasFlag(AnimationControlEvents.Jump))
                {
                    Controller.Jump();
                }

                if (mAnimationStateMachine.ActiveControlEvents.HasFlag(AnimationControlEvents.Boost))
                {
                    OnStateChanged(ControllerState.Boosting);
                }
            }
            else // Just let the events happen immediately:
            {
                if (Controller.SupportFinder.HasSupport)
                {
                    if ((DesiredMovementActions & MovementActions.Jumping) > 0)
                    {
                        Controller.Jump();
                    }

                    if (DesiredMovementActions.HasFlag(MovementActions.Boosting) &&
                        mState == ControllerState.Neutral &&
                        mBooster != null &&
                        mBooster.BoostReady)
                    {
                        OnStateChanged(ControllerState.Boosting);
                    }
                }
            }

            if (mState == ControllerState.Boosting &&
                !(DesiredMovementActions.HasFlag(MovementActions.Boosting)))
            {
                OnStateChanged(ControllerState.Neutral);
            }
        }