P
P
Pavel Subbotin2021-01-14 17:34:46
Unity
Pavel Subbotin, 2021-01-14 17:34:46

How to fix the walking bug?

In general, when my character tries to walk on a horizontal surface, he bugs and does not want to go further. How to fix it? RigidBody Video : Collider: Walk Script:

600055c8ab7f7473730525.png
60005613ee6aa397797354.png

public float speed = 10f;
    Rigidbody2D rb;
    public float move = 0f;
    public bool isGround = false;
    public float jumpForce = 6f;

void Update()
    {
        if(move == 0) {
            animator.SetFloat("Speed", 0);
        }else animator.SetFloat("Speed", Mathf.Abs(move));

        transform.Translate(transform.right * move * speed * Time.deltaTime);
    }

public void Jump() {
        if (isGround && !isUp && !PausePanel.activeSelf) {
            rb.AddForce(transform.up * jumpForce, ForceMode2D.Impulse);
            animator.SetTrigger("TakeOf");
        }
    }

Answer the question

In order to leave comments, you need to log in

1 answer(s)
C
CHIDWI, 2021-01-15
@CHIDWI

In general, the previous answer is completely correct. If you want to do the movement in this way, then you can add Vector3.up. so that the hero always pulls a little up, it is not visually noticeable, but it allows you to walk along the "inclined" one)).

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question