Only sideways colliding detection

Wassup, I’m making a video game (what a surprise :stuck_out_tongue: ) in 2D.

When I’m jumping into wall in my game (eg. it’s on my right side) and if I hold right arrow and when my character hit wall he stays in air bugging with the wall.
I’ve tried making raycast wall detection but it worked only partly (when ray wasn’t hitting platform character was still bugging with wall).
How to repair this (it ain’t have to be raycast solution)?

here’s my working part of raycast wall detection:

    bool RCheck()              //does he touch wall on right?
        Vector2 position = transform.position;
        Vector2 direction = Vector2.right;
        float distance = 1.0f;

        RaycastHit2D hit = Physics2D.Raycast(position, direction, distance, groundLayer);
        if (hit.collider != null)
            return true;
        return false;

Create a collider that extrudes slightly from your object on the sides you want to detect it on. Run the script from those.

Hi there,
I’ve done some changes in my project, and I have another problem xD
As @SoshJam wrote, I created mask on sides of my character to check colliding and I wrote some code for them, but it doesn’t work, because it always return false.

Under character I created sprite mask and I gave them “background” sprite, so they are transparent.

Here’s code:

    public LayerMask Ground;
    Collision2D coll;
    public bool LC;

    public void OnCollisionEnter2D(Collision2D coll)

        if (coll.gameObject.layer == Ground)
            LC = true;
            LC = false;