Esempio n. 1
0
    void FixedUpdate()
    {
        if (playerVelocity > 0)
        {
            GetComponent <Rigidbody2D>().velocity = new Vector2(GetComponent <Rigidbody2D>().velocity.x + playerVelocity, GetComponent <Rigidbody2D>().velocity.y);
            transform.localScale = new Vector3(faceRight, 1f, 1f);
            mattyFactor          = 1.0f;
        }

        if (playerVelocity < 0)
        {
            GetComponent <Rigidbody2D>().velocity = new Vector2(GetComponent <Rigidbody2D>().velocity.x + playerVelocity, GetComponent <Rigidbody2D>().velocity.y);
            transform.localScale = new Vector3(faceLeft, 1f, 1f);
            mattyFactor          = -1.0f;
        }

        if (playerVelocity == 0 && !status.getHanging() && status.getGrounded() && GetComponent <Rigidbody2D>().velocity.x != 0)
        {
            //changeFriction(0.4f);
            if (GetComponent <Rigidbody2D>().velocity.x < 0)
            {
                GetComponent <Rigidbody2D>().velocity = new Vector2(GetComponent <Rigidbody2D>().velocity.x + drag, GetComponent <Rigidbody2D>().velocity.y);
            }
            else if (GetComponent <Rigidbody2D>().velocity.x > 0)
            {
                GetComponent <Rigidbody2D>().velocity = new Vector2(GetComponent <Rigidbody2D>().velocity.x - drag, GetComponent <Rigidbody2D>().velocity.y);
            }

            if (GetComponent <Rigidbody2D>().velocity.x > -dragLimit && GetComponent <Rigidbody2D>().velocity.x < dragLimit)
            {
                GetComponent <Rigidbody2D>().velocity = new Vector2(0, GetComponent <Rigidbody2D>().velocity.y);
            }
        }



        if (Mathf.Abs(GetComponent <Rigidbody2D>().velocity.x) > status.getMaxSpeed() && !status.getKnocked())
        {
            //Subtracts player velocity when over max speed, keeping the net gain at 0
            //GetComponent<Rigidbody2D>().velocity = new Vector2(GetComponent<Rigidbody2D>().velocity.x - playerVelocity, GetComponent<Rigidbody2D>().velocity.y);

            if (GetComponent <Rigidbody2D>().velocity.x > 0)
            {
                GetComponent <Rigidbody2D>().velocity = new Vector2(status.getMaxSpeed(), GetComponent <Rigidbody2D>().velocity.y);
            }
            else if (GetComponent <Rigidbody2D>().velocity.x < 0)
            {
                GetComponent <Rigidbody2D>().velocity = new Vector2(-status.getMaxSpeed(), GetComponent <Rigidbody2D>().velocity.y);
            }
        }

        testSpeed = GetComponent <Rigidbody2D>().velocity.x;
    }