I am looking for a code which makes sure the character is grounded when the game starts,Is there a code to make sure the character is grounded when the game starts?

(I am using Character Controller)

I am looking for a code which makes sure the character is grounded when the game starts, i am a noob in unity so please explain if i have to add a component etc.,I am looking for a code which makes sure the character is grounded when the game starts, i am a beginner in unity so i do not know.

Assuming you’re using a default capsule. Add a sphere collider and edit the collider’s parameters as follows:

  • IsTrigger: Yes
  • Center: 0, -0.6, 0
  • Radius: 0.45

.

Now in a script attached to that gameobject:

public class GroundedScript : MonoBehaviour
{
    private bool isGrounded = false;

    private void OnTriggerEnter(Collider other)
    {
        // Grounded
        isGrounded = true;
    }

    private void OnTriggerExit(Collider other)
    {
        // Ungrounded
        isGrounded = false;
    }
}

Something like this?