'Physics.Raycast Grounddrag system not working

I'm trying to implement a unity FPS Rigid body movement controller into my Unity 3d project. However I cannot seem to add drag to my player. I've been trying to do it with the following code:

private void Update()
    {
        //Ground check

        grounded = Physics.Raycast(transform.position, Vector3.down, playerHeight * 0.5f + 0.2f, whatIsGround);

        MyInput();

        //Handle drag
        if (grounded)
        {
            rb.drag = groundDrag;
        }
        else
        {
            rb.drag = 0;
        }
        
    }

Anyone have an idea as to what else I could try to add or fix with the script?



Solution 1:[1]

If you defined the ground layer in the inspector, the problem seems to be here. Fix it with only replace whatIsGround to whatIsGround.value.

public LayerMask whatIsGround;
private void Update()
{
    grounded = Physics.Raycast(transform.position, Vector3.down, playerHeight * 0.5f + 0.2f, whatIsGround.value);
}

Sources

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

Source: Stack Overflow

Solution Source
Solution 1