Ejemplo n.º 1
0
    public void GrabWall()
    {
        states.isGrabbed = true;

        states.dontMoveX     = false;
        states.hasAirJumped  = false;
        states.hasTeleported = false;

        states.isAffectedByGravity = false;
        movement.SetVelocityX(0, false);
        movement.SetVelocityY(0, false);

        frontColliderInput.SetConnectToMovingPlatforms(true);

        StartCoroutine(WhileGrabbed());
    }
    void Update()
    {
        if (states.isAffectedByGravity)
        {
            //Make bottom edge collider connect to moving platforms
            if (!belowColliderInput.GetConnectToMovingPlatforms())
            {
                belowColliderInput.SetConnectToMovingPlatforms(true);
            }

            //Apply gravity;
            if (velocity.y <= 0)
            {
                velocity.y += -gravity * 3 * Time.deltaTime;
            }
            else
            {
                velocity.y += -gravity * Time.deltaTime;
            }
        }
        else
        {
            //Make bottom edge collider not connect to moving platforms
            belowColliderInput.SetConnectToMovingPlatforms(false);
        }

        //Stop moving vertically if hitting ceiling or ground
        if (velocity.y > 0 && states.isTouchingCeiling)
        {
            velocity.y = 0;
        }

        if (velocity.y < 0 && states.isTouchingGround)
        {
            velocity.y = 0;
        }
    }