Esempio n. 1
0
 private void changeState(AnimationItem currentAnimation)
 {
     if (currentAnimation.GetVector().y > 0)
     {
         state = State.climbing;
     }
     else if (currentAnimation.GetVector().y == 0)
     {
         if (animationQueue.Count != 0 && animationQueue.Peek().GetVector().y != 0)
         {
             state = State.falling;
         }
         else
         {
             state = State.moving;
         }
     }
 }
Esempio n. 2
0
    public void HandleMovement()
    {
        if (movementPercentageElapsed >= 1) // If no animation is playing
        {
            foreach (GameObject member in party)
            {
                if (transform.tag == "Player" && member.GetComponent <PartyMovement>().isMoving) // Waits for all animations to end
                {
                    return;
                }
            }

            if (animationQueue.Count == 0 && userInputQueue.Count == 0)
            {
                CheckHoldInput();
            }

            if (animationQueue.Count == 0 && userInputQueue.Count != 0) // If there is no animation and an input Validates the input, it's up here so it starts in the same frame it validates
            {
                ValidateInput(userInputQueue.Dequeue());
            }

            if (animationQueue.Count != 0) // If there is an animation queued
            {
                currentAnimation = animationQueue.Dequeue();

                changeState(currentAnimation);
                updateDirection(currentAnimation.GetVector());

                if (currentAnimation.SavePosition()) // if it's supposed to save its position, used for the next in party
                {
                    SavePosition();
                }

                if (currentAnimation.TriggerParty()) // Triggers next in party to start animation with new saved animations
                {
                    TriggerNextInParty(currentAnimation.getPartySwap());
                }

                movementPercentageElapsed = 0;
                isMoving = true;
            }
        }
        if (movementPercentageElapsed < 1) // Handles the actual animation frame by frame
        {
            float delta = Time.deltaTime * currentAnimation.GetSpeed();

            float deltaPercentage = delta / currentAnimation.GetVector().magnitude;
            if (movementPercentageElapsed + deltaPercentage > 1)
            {
                deltaPercentage = (1 - movementPercentageElapsed);
            }
            transform.Translate(currentAnimation.GetVector() * deltaPercentage, Space.World);
            movementPercentageElapsed += deltaPercentage;

            if (movementPercentageElapsed == 1 && animationQueue.Count == 0 && userInputQueue.Count == 0) // if there is no more animations and it's the end toggles isMoving, saves a frame
            {
                isMoving = false;
                state    = State.still;
                CheckIfDitched(); // At the end of an animation checks to see if party members were ditched
            }
        }
    }