public void StopPushing()
 {
     if (currentPushable)
     {
         currentPushable.EndPushing();
     }
 }
    // Hard coded pushing used instead of rigidbody pushing in order to set distance between player and pushable for proper animation spacing.
    // Since current art is pixel-based, the pushable can look a little shaky. Working on a fix for this.

    public void CheckForPushing() // State Machine Behaviour function. Checks if pushable is on the correct side, in the list of pushables.
    {
        bool     pushableOnCorrectSide = false;
        Pushable previousPushable      = currentPushable;

        currentPushable = null;

        if (currentPushables.Count > 0)
        {
            bool movingRight = PlayerInput.Instance.Horizontal.Value > float.Epsilon;
            bool movingLeft  = PlayerInput.Instance.Horizontal.Value < -float.Epsilon;

            for (int i = 0; i < currentPushables.Count; i++)
            {
                float pushablePosX = currentPushables[i].pushablePosition.position.x; // Sets player position to set pushable position for proper animation spacing.
                float playerPosX   = transform.position.x;
                if (pushablePosX < playerPosX && movingLeft || pushablePosX > playerPosX && movingRight)
                {
                    pushableOnCorrectSide = true;
                    currentPushable       = currentPushables[i];
                    break;
                }
            }

            if (pushableOnCorrectSide)
            {
                Vector2 moveToPosition = movingRight ? currentPushable.playerPushingRightPosition.position : currentPushable.playerPushingLeftPosition.position;
                moveToPosition.y = characterController2D.Rigidbody.position.y;
                characterController2D.Teleport(moveToPosition);
            }
        }

        if (previousPushable != null && currentPushable != previousPushable)
        {
            previousPushable.EndPushing();
        }

        animator.SetBool(hashPushingPara, pushableOnCorrectSide); // Set animation state pushing parameter to switch to pushing State Machine Behaviour.
    }
Exemplo n.º 3
0
    public void CheckForPushing()
    {
        bool     pushableOnCorrectSide = false;
        Pushable previousPushable      = currentPushable;

        currentPushable = null;

        if (currentPushables.Count > 0)
        {
            bool movingRight = PlayerInput.Instance.Horizontal.Value > float.Epsilon;
            bool movingLeft  = PlayerInput.Instance.Horizontal.Value < -float.Epsilon;

            for (int i = 0; i < currentPushables.Count; i++)
            {
                float pushablePosX = currentPushables[i].pushablePosition.position.x;
                float playerPosX   = transform.position.x;
                if (pushablePosX < playerPosX && movingLeft || pushablePosX > playerPosX && movingRight)
                {
                    pushableOnCorrectSide = true;
                    currentPushable       = currentPushables[i];
                    break;
                }
            }

            if (pushableOnCorrectSide)
            {
                Vector2 moveToPosition = movingRight ? currentPushable.playerPushingRightPosition.position : currentPushable.playerPushingLeftPosition.position;
                moveToPosition.y = characterController2D.Rigidbody.position.y;
                characterController2D.Teleport(moveToPosition);
            }
        }

        if (previousPushable != null && currentPushable != previousPushable)
        {
            previousPushable.EndPushing();
        }

        animator.SetBool(hashPushingPara, pushableOnCorrectSide);
    }