Esempio n. 1
0
    public virtual void StopMoving()
    {
        canMove     = false;
        isAttacking = false;

        if (sceneAnimator)
        {
            sceneAnimator.SetFloat("Speed", 0, this.gameObject);
            sceneAnimator.SetBool("IsGrounded", true, this.gameObject);
            sceneAnimator.SetBool("Attacking", false, this.gameObject);
        }
    }
Esempio n. 2
0
    protected void Move()
    {
        isGrounded = IsItGrounded();

        if (IsJumping(isGrounded))
        {
            justJumped = true;
            if (localPlayer)
            {
                SoundManager sManager = FindObjectOfType <SoundManager>();
                sManager.PlaySound(gameObject, GameSounds.PlayerJump, false);
            }
            speedY = maxYSpeed * directionY;
            StartCoroutine(WaitJumping());
        }
        else
        {
            speedY = rb2d.velocity.y;
        }

        if (IsGoingRight())
        {
            // Si estaba yendo a la izquierda resetea la aceleración
            if (directionX == -1)
            {
                ResetDirectionX(1);
            }

            // sino acelera
            else if (acceleration < maxAcceleration)
            {
                Accelerate();
            }

            actualSpeed = maxXSpeed * acceleration;
            speedX      = actualSpeed;
        }
        else if (IsGoingLeft())
        {
            // Si estaba yendo a la derecha resetea la aceleración
            if (directionX == 1)
            {
                ResetDirectionX(-1);
            }

            // sino acelera
            else if (acceleration < maxAcceleration)
            {
                Accelerate();
            }

            actualSpeed = maxXSpeed * acceleration;
            speedX      = -actualSpeed;
        }
        else
        {
            speedX       = 0f;
            acceleration = 0;
        }

        if (lastPosition != transform.position)
        {
            if (sceneAnimator)
            {
                sceneAnimator.SetFloat("Speed", Mathf.Abs(rb2d.velocity.x), this.gameObject);
                sceneAnimator.SetBool("IsGrounded", isGrounded, this.gameObject);
            }
        }

        rb2d.velocity = new Vector2(speedX, speedY);
        lastPosition  = transform.position;
    }