Player jumps very high for the first time and then goes smoothly.

I don’t know if this is a problem with my script or scene ( probably scene ). For the first time in playmode when I press jump button the player jump very high, almost off the screen. Then after that, it goes normally. Here is the script that I am using for jumping.

public static bool reachedEnd;
    public float jumpForce;
    public static bool isDied;
    public static bool canJump;

    public GameObject player;
    private Collider2D playerCollider;
    private Rigidbody2D playerRB;
    public Collider2D obstacleCollider;
    public Collider2D groundCollider;

    void Awake()
    {
        isDied = false;
        playerCollider = player.GetComponent<Collider2D> ();
        playerRB = player.GetComponent<Rigidbody2D> ();
    }

    void Update()
    {
        if( playerCollider.IsTouching(obstacleCollider))
            isDied = true;
    }

    void FixedUpdate()
    {
        if (Input.GetKeyDown(KeyCode.W) && grounded() && isDied == false)
        {
            playerRB.AddForce (transform.up * jumpForce,0);
        }

        print (isDied);
    }

    bool grounded()
    {
        bool grounded = false;
       
        if(playerCollider.IsTouching(groundCollider))
            {
                grounded = true;
            }
        return grounded;
    }

Have you tried debugging the code to see why it happens?

I don’t really see anything wrong with the code at first glance.

In what position does the character start? Usually you want to spawn the character so his collider is slightly above the ground collider so he can fall down naturally.

Actually the problem with the initial velocity of the GameObject. So before jumping, I nullified the velocity of the GameObject and problem was solved.