Make character sense ground to determine what animations can play

I made a bool called “grounded” for an animation controller, so that anytime my character is on the ground, it can only do certain animations. But how do I make it know when it’s on the ground, so it can only do idle or walking animations on the floor, and jumping animations in air?Also are there any other ways of doing so?

my code:

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

public class Anim : MonoBehaviour
{
    Animator animator;

    [SerializeField, Tooltip("Transform where grounded will be checked")] private Transform isGroundedPoint;

[SerializeField, Tooltip("The range of the grounded point")] private float isGroundedRange;

[SerializeField, Tooltip("Ground Layer")] private LayerMask isGroundedLayer;
    // Start is called before the first frame update
    void Start()
    {
        animator = GetComponent<Animator>();
        
    }

    // Update is called once per frame
    void Update()
    {
        if (Input.GetKey("w"))
        {
            animator.SetBool("Walking", true);
        }
    }

    private bool grounded()
    {
        Collider[] collisions  = Physics.OverlapSphere(isGroundedPoint.position,
            isGroundedRange, isGroundedLayer.value);

        return collisions.Length > 0;
    }
}

Are you using the Rigidbody component or the CharacterController component?
If it’s CharacterController, you can use the IsGrounded() method.

More about this in the docs:

(Note: here is the previous thread: How to make character sense ground)

You have the function to detect if the character is grounded, but you never call this function or send the information to the animator.

If you want the animator to know that grounded state, then you need to call grounded() during Update() and use SetBool to set the animator state, just like you have done for Walking.