Esempio n. 1
0
 // Update is called once per frame
 void Update()
 {
     if (Input.GetButtonDown("Jump") && status.getHanging())
     {
         wallJumped = true;
     }
 }
    // Update is called once per frame
    void Update()
    {
        //Checks for the jump button press
        if (Input.GetButtonDown("Jump") && (status.getGrounded() || status.getHanging()))
        {
            jumped = true;
        }

        if (Input.GetButtonDown("Jump") && !(status.getGrounded() || status.getHanging()) && numberOfJumps > 0)
        {
            doubleJumped = true;
        }

        if (status.getGrounded() || status.getHanging())
        {
            numberOfJumps = 1;
            doubleJumped  = false;
        }
    }
Esempio n. 3
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;
    }