在斜坡上时的坠落动画

Falling animation when on slopes

我对所有这一切都很陌生,对于菜鸟的错误,我们深表歉意。 我建立了一个我非常满意的状态机,只有一个问题,每当玩家跳上斜坡并保持 运行(向上或向下)时,动画不会切换到 运行 并保持下降状态。

 private void FixedUpdate()
    {
        GroundCheck();

        if (state != State.hurt)
        {
            Movement();
            DoubleJump();
            StateMachine();
        }

        HurtCheck();
        anim.SetInteger("state", (int)state);
    }

private void Movement()
    {
        float hDirection = Input.GetAxis("Horizontal");

        //holding down "D" makes the value positive and vice versa
        if (hDirection < 0)
        {
            rb.velocity = new Vector2(-speed, rb.velocity.y);
            transform.localScale = new Vector2(-1, 1);
        }
        else if (hDirection > 0)
        {
            rb.velocity = new Vector2(speed, rb.velocity.y);
            transform.localScale = new Vector2(1, 1);
        }
        else
        {

        }

        if (Input.GetButtonDown("Jump") && isGrounded == true)
        {
            Jump();
        }
    }

private void StateMachine()
    {
        if(rb.velocity.y > 2f && isGrounded == false)
        {
            state = State.jumping;
        }

        if(rb.velocity.y < 2f && isGrounded == false)
        {
            state = State.falling;
        }

        if(rb.velocity.y == 0 && Mathf.Abs(rb.velocity.x) > 2f)
        {
            state = State.running;
        }

        if(rb.velocity.magnitude == 0)
        {
            state = State.idle;
        }
    }

您似乎打算 rb.velocity.y 在斜坡上时大于 0。但是为了进入运行ning状态你有一个条件就是rb.velocity.y == 0。如果你想 运行 在斜坡上,那么也许你应该像这样改变那个条件。

    if((rb.velocity.y < 2f) && (Mathf.Abs(rb.velocity.x) > 2f))
    {
        state = State.running;
    }