Raycast is not setting false, however is able to be set to true.

I have a raycast that checks to see if the player is grounded. When it hits the ground, the bool “Grounded” is set to true, and when it does not hit the ground, bool is set to false. Problem is that moment it hits the ground it stays true and when it doesn’t hit the ground it doesn’t change to false unless I change it in the inspector.

    private void FixedUpdate(){

    if (Grounded)
    {
        Debug.Log("Grounded");
    }

    if (Physics.Raycast(PlayerRaycastStartPoint.position,
           PlayerRaycastStartPoint.forward, out groundhit, RaycastDistance))
    {
        if (groundhit.collider.tag == "Ground")
        {
            Grounded = true;
        }

    }
    else
    {
        Grounded = false;
    }
    }

When your raycast is hitting something it checks the gameobject’s tag to determine if its grounded. It doesnt set isGrounded to false if it tag does not equal “Ground”.

Don’t use else, use:

if (groundhit.collider.tag !== "Ground") {
Grounded = false;
}

The ! stands for not, so it converts equals to not equals.

Try these:

private void FixedUpdate(){

     if (Physics.Raycast(PlayerRaycastStartPoint.position, PlayerRaycastStartPoint.forward, out groundhit, RaycastDistance) && groundhit.collider.tag == "Ground")
     {
         Grounded = true;
     } else {
         Grounded = false;
     }

     Debug.Log("Grounded = " Grounded);
     Debug.Log("groundhit.collider.tag = " groundhit.collider.tag);
}

or

private void FixedUpdate(){

    Grounded = (Physics.Raycast(PlayerRaycastStartPoint.position, PlayerRaycastStartPoint.forward, out groundhit, RaycastDistance) && groundhit.collider.tag == "Ground") ? true : false;

    Debug.Log("Grounded = " Grounded);
    Debug.Log("groundhit.collider.tag = " groundhit.collider.tag);
}