Physics.CheckCapsule() not working.

OK so i’ve been trying to get this right for a while now and its just not happening. I have a rigidbody as a player and i want to user the CheckCapsule function to detect whether the player is grounded. My understanding of the function was that if I specify 2 points, a point just below the player and a point in the center of the player, and then specify a radius, it would return true only if those points had come in contact with another object. Here’s my code.

centerOfPlayer = transform.position;
bottomOfPlayer = new Vector3(transform.position.x, transform.position.y - (ColliderComponent.radius + 0.01f), transform.position.z);

I then plug these 2 vectors into the function.

bool isGrounded = Physics.CheckCapsule(centerOfPlayer,bottomOfPlayer,ColliderComponent.radius/2);\

For some reason this always returns true. I do have GUI components over the top of my player, could it be that somehow the function thinks its colliding with them?

Any help would be much appreciated. Thanks.

The CapsuleCheck() was returning true because it was hitting the players collider (duh). I fixed this by adding a Layermask mask variable to my player controller script, setting that to default and moving my player into another layer “Player”. Then added the mask to the end of the CheckCapsule() function.

bool isGrounded()
	{
  		return (Physics.CheckCapsule(centerOfPlayer,bottomOfPlayer,ColliderComponent.radius - 0.05f, 

mask.value));	 
	}

The points you are defining are the axis of the capsule. From a side view:

12113-capsule.png

Your two points are the red and green points below. The radius is the radius of the half spheres at the ends. So if you place one of the points just below your character, you are covering a ‘radius’ distance below the point you specify.