Пример #1
0
    void FixedUpdate()
    {
        //isMoving = false;
        switchBreakerCount = 0;

        UpdateInputs();

        if (inventory)
        {
            combatModule.LoadAttacks();
        }

        //Detect if there are any transitions (once the current state has ended)
        if (currentLagFrames == 0)
        {
            currentState = Transition(true);
        }
        //Detect if there are any cancel transitions
        currentState = Transition(false);

        switch (currentState)
        {
        case State.Idle:
            switchBreakerCount++;
            if (switchBreakerCount > 10)
            {
                Debug.Log("Stuck! Broke at: " + currentState); break;
            }

            if (physics.rb.velocity.y >= -.5 && physics.rb.velocity.y <= .5)
            {
                physics.LockRotation(true);
            }
            else
            {
                physics.LockRotation(false);
            }

            if (IsGrounded && fastFallDown)
            {
                physics.Platformdrop(m_PlatdropFrames);
            }

            break;

        case State.Walk:
            switchBreakerCount++;
            if (switchBreakerCount > 10)
            {
                Debug.Log("Stuck! Broke at: " + currentState); break;
            }

            //isMoving = true;

            if (IsGrounded && fastFallDown)
            {
                physics.Platformdrop(m_PlatdropFrames);
            }

            physics.Walk(playerInputMovementVector);
            physics.LockRotation(false);

            break;

        case State.InitialRun:
            switchBreakerCount++;
            if (switchBreakerCount > 10)
            {
                Debug.Log("Stuck! Broke at: " + currentState); break;
            }

            //isMoving = true;

            if (angleDiff > m_TurnaroundAngleThreshold)
            {
                currentLagFrames = m_InitialRunFrames;
            }
            if (currentLagFrames == m_InitialRunFrames)
            {
                runDustParticles.Play();
            }
            if (playerInputMovementVector != Vector3.zero)
            {
                physics.Run(playerInputMovementVector);
            }

            if (IsGrounded && fastFallDown)
            {
                physics.Platformdrop(m_PlatdropFrames);
            }

            currentLagFrames--;
            physics.LockRotation(false);

            break;

        case State.Run:
            switchBreakerCount++;
            if (switchBreakerCount > 10)
            {
                Debug.Log("Stuck! Broke at: " + currentState); break;
            }

            //isMoving = true;

            if (playerInputMovementVector == Vector3.zero && IsGrounded)
            {
                currentLagFrames--;
            }
            else
            {
                currentLagFrames = m_MinInactiveFramesIoIdle;
                physics.Run(playerInputMovementVector);
            }

            if (IsGrounded && fastFallDown)
            {
                physics.Platformdrop(m_PlatdropFrames);
            }

            physics.LockRotation(false);

            break;

        case State.Crouching:
            switchBreakerCount++;
            if (switchBreakerCount > 10)
            {
                Debug.Log("Stuck! Broke at: " + currentState); break;
            }

            if (IsGrounded && fastFallDown)
            {
                physics.Platformdrop(m_PlatdropFrames);
            }

            //physics.Crouching(playerInputMovementVector, cameraForward, joystickAngle);
            physics.LockRotation(true);

            break;

        case State.Turnaround:
            switchBreakerCount++;
            if (switchBreakerCount > 10)
            {
                Debug.Log("Stuck! Broke at: " + currentState); break;
            }

            if (playerInputMovementVector != Vector3.zero && currentLagFrames <= m_TurnaroundFrames - m_TurnaroundDeaccelFrames)
            {
                physics.Run(playerInputMovementVector);
            }
            if (currentLagFrames == m_TurnaroundFrames)
            {
                turnaroundDustParticles.Play();
                physics.LockRotation(playerInputMovementVector);
            }

            if (IsGrounded && fastFallDown)
            {
                physics.Platformdrop(m_PlatdropFrames);
            }

            currentLagFrames--;

            break;

        case State.Jumpsquat:
            switchBreakerCount++;
            if (switchBreakerCount > 10)
            {
                Debug.Log("Stuck! Broke at: " + currentState); break;
            }

            if (currentLagFrames == m_JumpSquatFrames)
            {
                physics.LockRotation(true);
            }
            if (playerInputMovementVector != Vector3.zero)
            {
                physics.AirMove(playerInputMovementVector);
            }

            currentLagFrames--;

            break;

        case State.Dodge:
            switchBreakerCount++;
            if (switchBreakerCount > 10)
            {
                Debug.Log("Stuck! Broke at: " + currentState); break;
            }

            if (currentLagFrames == m_TotalDodgeDuration - m_DodgeStartupFrames)
            {
                IsVulnerable           = false;
                temporaryVector        = playerInputMovementVector.normalized;
                temporaryJoystickAngle = joystickAngle;
                physics.LockRotation(playerInputMovementVector);
            }
            if (currentLagFrames <= m_TotalDodgeDuration - m_DodgeStartupFrames && currentLagFrames > m_DodgeEndLagFrames)
            {
                physics.GroundDodge(temporaryVector);
            }
            if (currentLagFrames == m_DodgeEndLagFrames)
            {
                IsVulnerable = true;
            }

            currentLagFrames--;

            break;

        case State.Wavedash:
            switchBreakerCount++;
            if (switchBreakerCount > 10)
            {
                Debug.Log("Stuck! Broke at: " + currentState); break;
            }

            if (currentLagFrames == m_WavedashFrames)
            {
                physics.Wavedash(temporaryVector);
                turnaroundDustParticles.Play();
            }

            if (IsGrounded && fastFallDown)
            {
                physics.Platformdrop(m_PlatdropFrames);
            }

            currentLagFrames--;

            break;

        case State.Attack:
            switchBreakerCount++;
            if (switchBreakerCount > 10)
            {
                Debug.Log("Stuck! Broke at: " + currentState); break;
            }

            if (currentLagFrames == -1)
            {
                //Detect what type of attack is being used
                CheckAttack();
                combatModule.InitializeAttack(currentAttack, out currentLagFrames);
                Debug.Log(currentAttack);
                if (playerInputMovementVector != Vector3.zero)
                {
                    physics.LockRotation(playerInputMovementVector);
                }
                //Still need start lag
                //Still need both end lags
            }
            else
            {
                combatModule.Attack(currentAttack, currentLagFrames);
            }

            currentLagFrames--;

            break;

        case State.Landing:
            switchBreakerCount++;
            if (switchBreakerCount > 10)
            {
                Debug.Log("Stuck! Broke at: " + currentState); break;
            }

            if (currentLagFrames == m_LandLagFrames)
            {
                physics.LockRotation(true);
                currentNumberOfJumps     = m_NumberOfJumpsInAir;
                currentNumberOfWallJumps = m_NumberOfWallJumps;
                currentNumberOfAirDodges = m_NumberOfAirDodges;
            }

            //Wait for transform to update to ground normal
            if (currentLagFrames == m_LandLagFrames - 2)
            {
                landDustParticles.Play();
            }

            if (playerInputMovementVector != Vector3.zero)
            {
                physics.AirMove(playerInputMovementVector);
            }

            currentLagFrames--;

            break;

        case State.LandingAttackLag:
            switchBreakerCount++;
            if (switchBreakerCount > 10)
            {
                Debug.Log("Stuck! Broke at: " + currentState); break;
            }

            break;

        case State.LandingHitstun:
            switchBreakerCount++;
            if (switchBreakerCount > 10)
            {
                Debug.Log("Stuck! Broke at: " + currentState); break;
            }

            break;

        case State.AscentJump1:
            switchBreakerCount++;
            if (switchBreakerCount > 10)
            {
                Debug.Log("Stuck! Broke at: " + currentState); break;
            }

            if (currentLagFrames == m_MaxJumpHeightExtendFrames)
            {
                physics.LockRotation(true);
                physics.Jump();
                physics.Jump();
                physics.Jump();
            }
            else if (currentLagFrames != 0 && currentLagFrames % 2 == 0)
            {
                physics.Jump();
            }

            if (!jumpButtonHeld)
            {
                currentLagFrames = 1;
            }

            if (playerInputMovementVector != Vector3.zero)
            {
                physics.AirMove(playerInputMovementVector);
            }

            currentLagFrames--;

            break;

        case State.InAir:
            switchBreakerCount++;
            if (switchBreakerCount > 10)
            {
                Debug.Log("Stuck! Broke at: " + currentState); break;
            }

            if (jumpButtonDown && currentNumberOfJumps > 0)
            {
                jumpDustParticles.Play();
                physics.AirJump();
                currentNumberOfJumps--;
            }

            if (playerInputMovementVector != Vector3.zero)
            {
                physics.AirMove(playerInputMovementVector);
            }

            if (!IsGrounded && fastFallDown && physics.rb.velocity.y < m_MinVelocityToFastfall)
            {
                physics.Fastfall();
            }

            break;

        case State.WallJump:
            switchBreakerCount++;
            if (switchBreakerCount > 10)
            {
                Debug.Log("Stuck! Broke at: " + currentState); break;
            }

            if (currentLagFrames == (m_WallJumpFrames - m_FramesToJumpOfWallJump))
            {
                physics.UpdateRotation();

                wallJumpDustParticles.Play();

                physics.WallJump(temporaryVector);
            }

            currentLagFrames--;

            break;

        case State.AirAttack:
            switchBreakerCount++;
            if (switchBreakerCount > 10)
            {
                Debug.Log("Stuck! Broke at: " + currentState); break;
            }
            break;

        case State.AirDodge:
            switchBreakerCount++;
            if (switchBreakerCount > 10)
            {
                Debug.Log("Stuck! Broke at: " + currentState); break;
            }

            if (currentLagFrames >= m_TotalDodgeDuration - m_DodgeStartupFrames)
            {
                physics.AirDodge(Vector3.zero);
                IsVulnerable           = false;
                temporaryVector        = playerInputMovementVector.normalized;
                temporaryJoystickAngle = joystickAngle;
                if (playerInputMovementVector != Vector3.zero)
                {
                    physics.LockRotation(playerInputMovementVector);
                }
                if (angleUp)
                {
                    temporaryVector.y = 1f;
                }
                if (angleDown)
                {
                    temporaryVector.y = -1f;
                }
                temporaryVector.Normalize();
                currentNumberOfAirDodges--;
            }
            if (currentLagFrames <= m_TotalDodgeDuration - m_DodgeStartupFrames && currentLagFrames > m_DodgeEndLagFrames)
            {
                physics.AirDodge(temporaryVector);
            }
            if (currentLagFrames == m_DodgeEndLagFrames)
            {
                IsVulnerable = true;
            }

            currentLagFrames--;

            break;

        case State.Hitstun:
            switchBreakerCount++;
            if (switchBreakerCount > 10)
            {
                Debug.Log("Stuck! Broke at: " + currentState); break;
            }
            break;

        default:
            Debug.Log("U H .  I don't know how we reached the default state.");
            break;
        }

        animator.SetBool(a_IsWalking, (currentState == State.Walk) ? true : false);
        animator.SetBool(a_IsRunning, (currentState == State.InitialRun || currentState == State.Run || currentState == State.Turnaround) ? true : false);
        animator.SetBool(a_IsCrouching, (currentState == State.Crouching) ? true : false);
        animator.SetBool(a_IsLanding, (currentState == State.Landing) ? true : false);
        animator.SetBool(a_IsGrounded, (IsGrounded) ? true : false);
        animator.SetFloat(a_AngleDifference, angleDiff);
        animator.SetBool(a_IsInJumpSquat, (currentState == State.Jumpsquat) ? true : false);
        animator.SetBool(a_IsAscendingJumpOne, (currentState == State.AscentJump1) ? true : false);
        animator.SetBool(a_IsWallJumping, (currentState == State.WallJump) ? true : false);
        animator.SetBool(a_IsDodging, (currentState == State.Dodge) ? true : false);
        animator.SetBool(a_IsWavedashing, (currentState == State.Wavedash) ? true : false);

        //Debug.Log(currentState + " " + currentLagFrames);
    }