'Cant Jump and run at the same time (Unity)

wont let me run and jump at the same time, movement works fine but when i sprint jump isnt registered i tried a few things but nothing was successful the character is a capsule and camera this is the relevant code:

    void UpdateMovement()
    {
        Vector2 targetDir = new Vector2(Input.GetAxisRaw("Horizontal"), Input.GetAxisRaw("Vertical"));
        targetDir.Normalize();

        currentDir = Vector2.SmoothDamp(currentDir, targetDir, ref currentDirVelocity, moveSmoothTime);


        if(controller.isGrounded)
        {
            if(Input.GetKeyDown(KeyCode.Space))
            {
                velocityY = 10.0f;
                Debug.Log("Jump");
            }
            else
            {
                velocityY = 0.0f;
                
            }
        }
        speed = walkSpeed;
        if(Input.GetKey(KeyCode.LeftShift))
        {
            //Debug.Log("Sprint");
            speed = walkSpeed * sprintMultiplier;
        }

        velocityY += gravity * Time.deltaTime;


        Vector3 velocity = transform.forward * currentDir.y * speed + transform.right * currentDir.x * speed + Vector3.up * velocityY;
        controller.Move(velocity * Time.deltaTime);
        //Debug.Log(speed);
    }

thank you in advance for any help



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source