How to jump through box colliders but jump on top of them

I need help with a script.
I’m currently working on a jumping game and I need help with one part.
The character is jumping from platform to platform fine but when he is going more up and comes to a place the platforms are almost blocking the way up he is not able to jump through the colliders.
How can I make this happen?
For an example see: Sonic jump, Doodle jump etc.

This is my script.

public float movementSpeed = 7;
private bool isGrounded = false;

void Update() {
    rigidbody.velocity = new Vector3(0, rigidbody.velocity.y, 0); //Set X and Z velocity to 0

    transform.Translate(Input.GetAxis("Horizontal") * Time.deltaTime * movementSpeed, 0, 0);

void Jump(){
    if (!isGrounded) { return; }
    isGrounded = false;
    rigidbody.velocity = new Vector3(0, 0, 0);
    rigidbody.AddForce(new Vector3(0, 700, 0), ForceMode.Force);        

void FixedUpdate(){
    isGrounded = Physics.Raycast(transform.position, -Vector3.up, 1.0f);
    if (isGrounded){
        Jump(); //Automatic jumping

Please write in C# thanks.

Here’s how I would do it. When the player presses jump, take the collider of the player, and change its layer to a new one, maybe name it “PassesThroughTerrain”. Configure your collision matrix so that that layer does not collide with the terrain’s physics layer. Unity - Manual: Layer-based collision detection

Then, when the player’s Y velocity reaches zero or negative, move it back to its usual layer so it won’t pass through anymore when it lands.

Also a better way to check for isGrounded is to have code in your OnCollisionEnter that checks the ContactPoint.normal. See if its Y is positive, if so, that means your player collided with something below it. Unity - Scripting API: ContactPoint.normal