Esempio n. 1
0
    public void Move(Vector3 dir)
    {
        Vector3 newScale = HelperUtilities.CloneVector3(transform.localScale);
        Vector3 newPos   = HelperUtilities.CloneVector3(transform.position);

        float delX;

        if (dir.x < 0)
        {
            delX       = -MoveSpeed;
            newScale.x = Mathf.Abs(newScale.x);
        }
        else if (dir.x > 0)
        {
            delX       = MoveSpeed;
            newScale.x = -Mathf.Abs(newScale.x);
        }
        else
        {
            delX = 0;
        }

        newPos.x += delX;

        transform.position   = Vector3.Lerp(transform.position, newPos, Time.fixedDeltaTime);
        transform.localScale = newScale;
    }
Esempio n. 2
0
    void Move()
    {
        if (inputDash && !isDashing && availableDash >= totalDash && LevelManager.Instance._isPlaying)
        {
            StartDashing();
        }

        Vector2 movement = new Vector2(inputHorizontal * walk, 0);

        if (isDashing)
        {
            movement       = HelperUtilities.CloneVector3(dashVector);
            availableDash -= Time.fixedDeltaTime;
            if (availableDash < 0)
            {
                StopDashing();
            }
        }

        if (!isDashing)
        {
            if (availableDash < totalDash)
            {
                availableDash += dashReplenish;
            }
        }

        if (LevelManager.Instance._isPlaying)
        {
            transform.Translate(movement * Time.fixedDeltaTime);
        }

        Vector3 newScale = HelperUtilities.CloneVector3(transform.localScale);

        if (movement.x > 0.0)
        {
            facingRight = true;
        }
        if (movement.x < 0.0)
        {
            facingRight = false;
        }
        if (movement.x > 0.0f && facingRight)
        {
            newScale.x = Mathf.Abs(newScale.x);
        }
        else if (movement.x < 0.0f && !facingRight)
        {
            newScale.x = Mathf.Abs(newScale.x) * -1;
        }

        isWalking            = Math.Abs(movement.x) > 0;
        transform.localScale = newScale;
    }
Esempio n. 3
0
    void TryJump()
    {
        if (isDashing)
        {
            return;
        }

        if (grounded && inputJump)
        {
            Vector3 velocity = HelperUtilities.CloneVector3(PM.rb2d.velocity);
            velocity.y       = 0;
            PM.rb2d.velocity = velocity;
            PM.rb2d.AddForce(Vector2.up * jump);
        }
    }