What is wrong with the jump?

I am trying to make a jump function for my test character. Everything in code appears to be fine. I use BoxCast to cast a box in the lower half of the character and check whether it collides with ‘Terrain’ layer. If it does, then a bool “OnGround” is enabled and player is able to jump. However, there is something wrong with it. When a player presses the “Jump” Button (which is space) at the time it lands, it can sort of clip and not be able to jump for a few clicks. It usually applies a force that pushes it up, but in that glitch it sort of does a very short jump and quickly lands not reaching the quarter of the height it is supposed to reach.
I suspect it might be something to do with collision detection.

More Info:
The character object has a box collider and a rigidbody. All rotation is frozen, none of position change is frozen. The collision detection mode is set to “Continuous Speculative”. Mass is 60, No drag or linear drag. No interpolation.

The ground object only has box collider, no rigidbody. It’s Layer is “Terrain”.

The only change done in physics is that gravity is -35 in the Y direction.

The settings for the Jump button in the Input settings:


Here is the code:

It is not necessarily a fix to the problem, rather, a workaround. There are four steps that helped me fix the problem. Not all of them might work for you. The fourth one really fixed the problem for me.

1.Turn the drag up on the player object.
2.In the script, try extending the box a little bit further than the size of the player.
3.If you have any code that is connected to player jump, movement, or input, in the FixedUpdate() method, transfer it to the Update() method. The FixedUpdate() method is usually used for physics.
4.(The important one). Do not use the AddForce method. (I think the bug might be tied to it, because the object occasionally clips a bit through the terrain, hence maybe when force is added there might be bugs.)
you can increase the players velocity in the y direction.(helped me)
rigidbody.velocity += new Vector3(0, jumpVelocity,0);