/// <summary>
        /// Checks for animation state transition. I.e. when ledge climb state should be changed based on the
        /// animation state.
        /// </summary>
        virtual protected void CheckForAnimationStateTransition()
        {
            AnimatorStateInfo info = myAnimator.GetCurrentAnimatorStateInfo(0);

            if (ledgeClimbState == LedgeClimbState.GRASPING)
            {
                if (info.IsName(AnimationState.LEDGE_HANG.AsString()))
                {
                    ledgeClimbState = LedgeClimbState.HANGING;
                }
            }
            else if (ledgeClimbState == LedgeClimbState.CLIMBING)
            {
                if ((info.IsName(AnimationState.LEDGE_CLIMB.AsString()) && info.normalizedTime >= 1) || info.IsName(AnimationState.LEDGE_DONE.AsString()))
                {
                    /// Don't do this transition in baked mode as we need to apply the transform in LateUpdate instead
                    if (animationTargetting != LedgeClimbAnimationTargetting.BAKED)
                    {
                        ledgeClimbState = LedgeClimbState.CLIMB_FINISHED;
                    }
                }
            }
            else if (ledgeClimbState == LedgeClimbState.DISMOUNTING)
            {
                if ((info.IsName(AnimationState.LEDGE_DISMOUNT.AsString()) && info.normalizedTime >= 1))
                {
                    ledgeClimbState = LedgeClimbState.DISMOUNT_FINISHED;
                }
            }
        }
        void LateUpdate()
        {
            // In baked mode we hard snap to the final position on all frames where the animator is in state LEDGE_DONE so the sprite doesn't jerk or fall off the ledge
            if (animationTargetting == LedgeClimbAnimationTargetting.BAKED && (ledgeClimbState == LedgeClimbState.CLIMBING || ledgeClimbState == LedgeClimbState.CLIMB_FINISHED))
            {
                AnimatorStateInfo info = myAnimator.GetCurrentAnimatorStateInfo(0);
                if (info.IsName(AnimationState.LEDGE_DONE.AsString()) || (info.IsName(AnimationState.LEDGE_CLIMB.AsString()) && info.normalizedTime >= 1.0f))
                {
                    Vector2 actualStandOffset = standOffset;
                    if (facingDirection == 1)
                    {
                        actualStandOffset.x *= -1;
                    }
                    Vector2 spriteOffset = (CurrentLedgePosition + actualStandOffset) - (Vector2)character.Transform.position;
                    character.Translate(spriteOffset.x, spriteOffset.y, true);
                    ledgeClimbState = LedgeClimbState.CLIMB_FINISHED;
                }
            }
            if (animationTargetting == LedgeClimbAnimationTargetting.BAKED && (ledgeClimbState == LedgeClimbState.DISMOUNTING || ledgeClimbState == LedgeClimbState.DISMOUNT_FINISHED))
            {
                AnimatorStateInfo info = myAnimator.GetCurrentAnimatorStateInfo(0);
                if (info.IsName(AnimationState.LEDGE_DISMOUNT_DONE.AsString()))
                {
                    // We assume here that dismounting returns you to the same spot as you started the grab
//					Vector2 actualOffset = ledgeOffset;
//					if (facingDirection == 1) actualOffset.x *= -1;
//					Vector2 spriteOffset = (CurrentLedgePosition - actualOffset) - (Vector2)character.Transform.position;
//					character.Translate (spriteOffset.x, spriteOffset.y, true);
                    ledgeClimbState = LedgeClimbState.DISMOUNT_FINISHED;
                }
            }
        }
 /// <summary>
 /// Called when the movement loses control. Override to do any reset type actions. You should
 /// ensure that character velocity is reset back to world-relative velocity here.
 /// </summary>
 override public void LosingControl()
 {
     // If we are doing anything other than reaching we should set y velocity back to 0
     if (ledgeClimbState != LedgeClimbState.REACHING)
     {
         character.SetVelocityY(0);
     }
     ledgeClimbState = LedgeClimbState.NONE;
     reachTimer      = 0.0f;
     facingDirection = 0;
 }
예제 #4
0
        /// <summary>
        /// Moves the character.
        /// </summary>
        override public void DoMove()
        {
            // Early out if falling
            if (fallTimer > 0.0f)
            {
                return;
            }

            // Check for fall key
            if (UserPressingFallKey())
            {
                if (ledgeClimbState == LedgeClimbState.HANGING || ledgeClimbState == LedgeClimbState.GRASPING)
                {
                    ledgeClimbState = LedgeClimbState.DISMOUNTING;
                    return;
                }
            }

            if (ledgeClimbState == LedgeClimbState.HANGING && UserPressingClimbKey())
            {
                ledgeClimbState = LedgeClimbState.CLIMBING;
            }


            switch (ledgeClimbState)
            {
            case LedgeClimbState.REACHING:
                character.DefaultAirMovement.DoMove();
                break;

            case LedgeClimbState.GRASPING:
                MoveToHangPosition();
                break;

            case LedgeClimbState.HANGING:
                MoveToHangPosition();
                break;

            case LedgeClimbState.DISMOUNTING:
                MoveToDismountPosition();
                break;
            }

            // TODO Only to this if required
            CheckForAnimationStateTransition();

            if (ledgeClimbState == LedgeClimbState.REACHING && CheckForGrab())
            {
                ledgeClimbState = LedgeClimbState.GRASPING;
            }
        }
 private void OnDisable()
 {
     IdleState.Dispose();
     MoveState.Dispose();
     JumpState.Dispose();
     InAirState.Dispose();
     LandState.Dispose();
     WallSlideState.Dispose();
     LedgeClimbState.Dispose();
     CrouchIdleState.Dispose();
     CrouchMoveState.Dispose();
     SwordAttackState.Dispose();
     HandAttackState.Dispose();
     AirAttackState.Dispose();
     SlideState.Dispose();
 }
 // <summary>
 /// Does the cling.
 /// </summary>
 override public void DoCling()
 {
     facingDirection = (int)character.Colliders[character.CurrentWallCollider].GetDirection().x;
     ledgeClimbState = LedgeClimbState.REACHING;
     reachTimer      = 0.0f;
 }
        /// <summary>
        /// Moves the character.
        /// </summary>
        override public void DoMove()
        {
            // Early out if falling
            if (fallTimer > 0.0f)
            {
                return;
            }

            // Check for fall key
            if (UserPressingFallKey())
            {
                if (ledgeClimbState == LedgeClimbState.HANGING || ledgeClimbState == LedgeClimbState.GRASPING)
                {
                    ledgeClimbState = LedgeClimbState.DISMOUNTING;
                    return;
                }
            }

            if (ledgeClimbState == LedgeClimbState.HANGING && UserPressingClimbKey())
            {
                ledgeClimbState = LedgeClimbState.CLIMBING;
            }


            switch (ledgeClimbState)
            {
            case LedgeClimbState.REACHING:
                character.DefaultAirMovement.DoMove();
                break;

            case LedgeClimbState.GRASPING:
                MoveToHangPosition();
                break;

            case LedgeClimbState.HANGING:
                MoveToHangPosition();
                break;

            case LedgeClimbState.DISMOUNTING:
                MoveToDismountPosition();
                break;
            }

            // TODO Only to this if required
            CheckForAnimationStateTransition();

            if (ledgeClimbState == LedgeClimbState.REACHING && CheckForGrab())
            {
                ledgeClimbState = LedgeClimbState.GRASPING;
                Platform p = character.CurrentWall.GetComponent <Platform> ();
                if (p != null)
                {
                    character.ParentPlatform = p;
                    if (facingDirection == 1)
                    {
                        character.ParentRaycastType = RaycastType.SIDE_RIGHT;
                    }
                    else
                    {
                        character.ParentRaycastType = RaycastType.SIDE_LEFT;
                    }
                }
            }
        }