Preventing player from sticking to the wall while jumping?

I’m working on a 2d platformer game for a school project. I know little about coding, here’s all I have so far.

[SerializeField] private float speed;
private Rigidbody2D body;
private Animator anim;
private bool grounded;

private void Awake()
{
    body = GetComponent<Rigidbody2D>();
    anim = GetComponent<Animator>();
}

private void Update()
{
    float horizontalInput = Input.GetAxis("Horizontal");
    body.velocity = new Vector2(horizontalInput * speed, body.velocity.y);

    if (horizontalInput > 0.01f)
        transform.localScale = Vector3.one;
    else if (horizontalInput < -0.01f)
        transform.localScale = new Vector3(-1, 1, 1);

    if (Input.GetKey(KeyCode.Space) && grounded)
        Jump();

    anim.SetBool("Running", horizontalInput != 0);
    anim.SetBool("grounded", grounded);
}

private void Jump()
{
    body.velocity = new Vector2(body.velocity.x, speed + 5);
    grounded = false;
}

private void OnCollisionEnter2D(Collision2D collision)
{
    if (collision.gameObject.tag == "Ground")
        grounded = true;
}        

The player can stick to a wall while jumping if you move into it. I want to fix that so the player always falls down. Does anyone know how to do that?

simply create a physic material that has low friction then apply it on the player collider (or even for wall collider if you want more smoothness!)

That helped, thanks! :slight_smile:

Thanks, that helped. But I found out that using “Platform Effector 2D” also helps.

The help states:
“The Platform Effector 2D applies various platform behavior such as one-way collisions, removal of side-friction/bounce and more.”