How to stop player from jumping inconsistently and more?

Okay, I know this seems super redundant because everyone has this problem but I haven’t found a full proof solution to mine… I’ve followed a YouTube tutorial for the movement and jump then looked at another for the jump and tried to combine the 2 for better results and still no success. Here is the movement script. I also have an issue of my player being too floaty how would I go about adding extra mass to the player but only while he comes down. and using keycode seems to act as press and hold but I want the jump to be the same height no matter which one you do, because i personally am heavy handed and hold keys down longer than i intend to.

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class PlayerMovement : MonoBehaviour
{
    [Header("Movement")]
    public float movementSpeed;
    public float groundDrag;

    public float jumpForce;
    public float jumpCoolDown;
    public float groundCheckDistance;
    private float bufferDistanceCheck = 0.1f;
    public bool canJump;

    [Header("Keybinds")]
    public KeyCode jumpKey = KeyCode.Space;

    [Header("Ground Check")]
    public LayerMask mask;

    public bool isGrounded;

    public Transform orientation;

    float horizontalInput;
    float verticalInput;

    Vector3 movementDirection;

    public Rigidbody rBody;
    CapsuleCollider playerHeight;

    private void Start()
    {
        playerHeight = GetComponent<CapsuleCollider>();
        rBody = GetComponent<Rigidbody>();
        rBody.freezeRotation = true;
        canJump = true;
    }

    private void Update()
    {
        MyInput();
        groundCheckDistance = (playerHeight.height / 2) + bufferDistanceCheck;
        RaycastHit hit;
        if(Physics.Raycast(transform.position, -transform.up, out hit, groundCheckDistance, whatIsGround))
        {
            isGrounded = true;
        }
        else
        {
            isGrounded = false;
        }
        // drag
        if (isGrounded)
        {
            rBody.drag = groundDrag;
        }
        else
        {
            rBody.drag = 0;
        }
    }

    private void FixedUpdate()
    {
        MovePlayer();
        SpeedControl();
    }

    private void MyInput()
    {
        horizontalInput = Input.GetAxisRaw("Horizontal");
        verticalInput = Input.GetAxisRaw("Vertical");

        //when to jump
        if(Input.GetKey(jumpKey) && canJump && isGrounded)
        {
            canJump = false;
            Jump();
            Invoke(nameof(ResetJump), jumpCoolDown);
        }
    }

    private void MovePlayer()
    {
        // calculate movement direction
        movementDirection = orientation.forward * verticalInput + orientation.right * horizontalInput;
        // on ground
        rBody.AddForce(movementDirection.normalized * movementSpeed * 10f, ForceMode.Force);

    }
    private void SpeedControl()
    {
        Vector3 flatvalue = new Vector3(rBody.velocity.x, 0f, rBody.velocity.z);

        //limit velocity if needed
        if(flatvalue.magnitude > movementSpeed)
        {
            Vector3 limitedValue = flatvalue.normalized * movementSpeed;
            rBody.velocity = new Vector3(limitedValue.x, rBody.velocity.y, limitedValue.z);
        }
    }
    private void Jump()
    {
        //reset y velocity
        rBody.velocity = new Vector3(rBody.velocity.x, 0f, rBody.velocity.z);
        rBody.AddForce(transform.up * jumpForce, ForceMode.Impulse);
    }
    private void ResetJump()
    {
        canJump = true;
    }
}

I can not add canJump = true or canJump = false here because it will break completely

            if(Physics.Raycast(transform.position, -transform.up, out hit, groundCheckDistance, whatIsGround))
            {
                isGrounded = true;
            }
            else
            {
                isGrounded = false;
            }

I have also provided a link to a clip i made of my issue, watch the inspector and you will see can jump is checked prior to isGrounded and isGrounded does not always check. if there is a way to fix this i would greatly appreciate it because I am stumped, please help! I also have a problem with the player sticking to objects when hitting them even with a physic material at 0.1 on dynamic friction

Demo Video

Hello. Following tutorials is good for starting, but you must “learn to learn”. You must understand how you can find the functions you need when want to do somethign different from the tutorial.

Go Unity manuals or look at google the correct question:

“Unity how to detect when a key is pressed once”

“Unity Detect the frame the jey is pressed”

“Unity Input detection one single time”


For key detection, there are 3 basic functions. Each function returns true in different ways:

-GetKey: returns true ALL FRAMES the key is beeing pressed

-GetKeyDown: returns true only at the FIRST FRAME the key is pressed

-GetKeyUp: returns true only at the LAST FRAME the key is pressed (actually is the first frame the key is released)

So for your jump you want GetKeyDown (not GetKey). Also, If your game will not be crossplatform (i mean only for PC) i also recommend to learn to use the KEYCODE forkey detections:

if (Input.GetKeyDown(KeyCode(LeftShift)))

if (Input.GetKeyDown(KeyCode(F)))

Remember, Learn to Learn!!!

Bye!