Disable being able to jump up a wall

Its my 2nd day with Unity, just finished the Roll’o ball game tutorial. I decided I wanted to make the game more unique and started adding some features. One I added was the ability to jump. This works great except when I’m up next to a wall. If I hit the wall at speed and spam spacebar, I can at time successfully continue to jump up the wall and over. I found Why is my Jump Height affected by Walls? - Unity Answers which reduced the cases of being able to jump up the wall, but I’m still able to in some cases.

Any tips on getting rid of the ability to jump higher against walls all together?

using UnityEngine;
using UnityEngine.UI;
using System.Collections;

public class PlayerController : MonoBehaviour
{
    public float speed;
    public Text countText;
    public Text winText;
    
    private Rigidbody rb;
    private int count;
    public bool grounded = true;

    void Start()
    {
        rb = GetComponent<Rigidbody>();
        count = 0;
        SetCountText();
        winText.text = "";
    }
    void FixedUpdate()
    {
        float moveHorizontal = Input.GetAxis("Horizontal");
        float moveVertical = Input.GetAxis("Vertical");

        Vector3 movement = new Vector3(moveHorizontal, 0.0f, moveVertical);
        rb.AddForce(movement * speed);

        if(Input.GetKeyDown (KeyCode.Space))
        {
            Jump();
        }
    }

    void Jump()
    {
        if(grounded == true)
        {
            rb.AddForce(new Vector3(0, 4, 0), ForceMode.Impulse);
            grounded = false;
        }
    }

    void OnCollisionEnter (Collision hit)
    {
        grounded = true;
    }

    void OnTriggerEnter(Collider other)
    {
        if(other.gameObject.CompareTag("Pick Up"))
        {
            other.gameObject.SetActive(false);
            count = count + 1;
            SetCountText();
        }
    }

    void SetCountText()
    {
        countText.text = "Count: " + count.ToString();
        if(count >= 10)
        {
            winText.text = "YOU WIN!";
        }
    }

}

Hi, I saw some suggested to use friction or drag and other methods within the rigid body, but I figured out it can be done by checking the hitPos on collision, so you can say which side of the platform was collided. Here is my suggestion, hope this will help someone.

private void OnCollisionStay2D(Collision2D collision)
{
    foreach (ContactPoint2D hitPos in collision.contacts)
    {
        if (hitPos.normal.x != 0) // check if the wall collided on the sides
            isGrounded = false; // boolean to prevent player from being able to jump
        else if (hitPos.normal.y > 0) // check if its collided on top 
        {
            isGrounded = true;
            print("grounded");
        }
        else isGrounded = false;
    }
}

After toying with it the rest of the weekend I did find one resolution that from my testing appears to work in all cases I had before.

I added a tag to all my walls, and added a case in the OnColliionEnter

     void OnCollisionEnter (Collision hit)
     {
         if(hit.gameObject.CompareTag("Wall"))
         {
            grounded = false;
         }
         else
         {
         grounded = true;
         }
     }

what I do is have a small box collider on the bottom of the char, and a big one on the top (if youre looking from top down view the top one should be bigger than the bottom)

then only run the code for the bottom collider, thus when you touch a wall, the top collider is hitting not the bottom one(which is used for the isGrounded)