help i have problems with groundcheck.

i made the game object, i created the code but my character still jumps mutiple times this is the code for my player:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Player : MonoBehaviour
{

public float moveSpeed;
float xInput, yInput;

Vector2 targetPos;

Rigidbody2D rb;

public float jumpForce;
bool isGrounded;
public Transform groundCheck;
public LayerMask groundlayer;

public Vector3 respawnPoint;
private void Awake()
{
rb = GetComponent();
}

// Start is called before the first frame update
void Start()
{
    
}

// Update is called once per frame
void Update()
{
   if(Input.GetKeyDown(KeyCode.Space)) 
   {
       if(isGrounded) 
       {
           Jump();
       }
       
   } 
   
}

private void FixedUpdate()
{
    xInput = Input.GetAxis("Horizontal");
    yInput = Input.GetAxis("Vertical");

    transform.Translate(xInput * moveSpeed, yInput * moveSpeed, 0);
    PlatformerMove();

isGrounded = Physics2D.OverlapCircle(groundCheck.position,0.2f,groundlayer);

}
void Jump()
{
    rb.velocity = Vector2.up * jumpForce;
}
void PlatformerMove() 
{ 
    rb.velocity = new Vector2(moveSpeed * xInput, rb.velocity.y);
}

void OnTriggerEnter2D(Collider2D other)
{
    if(other.tag == "Fall Detector")
    {
        transform.position = respawnPoint;
    }
    
    
       
    
}

}

You’ll need to debug the IsGrounded bool, to see if it actually changes as intended. Lots of reasons may cause the bool to stay true:


  1. Your player has the layer ‘Ground’ which means that the ground check picks up the player’s collider and sets IsGrounded to true.
  2. You did not assign any value to ‘GroundLayer’ in the inspector, so it’s set to its default value, which allows IsGrounded to be true when it picks up the player’s collider.

@CrayzoAs

-How does this even compile? OverlapCircle doesn’t have a boolean return value, so that’s your first problem.

-I have no idea what transform is inside your groundCheck variable

-Your cast radius is 0.2f which is incredibly small