I’m trying to use Physics.CheckCapsule to see if my character is grounded but I must be doing something wrong because it’s always returning true.
private float distToGround;
void Start()
{
// get the distance to ground
distToGround = GetComponent<Collider>().bounds.extents.y;
}
void Update()
{
Debug.Log(IsGrounded());
animator.SetBool("Airborn", IsGrounded());
// Movement
float Vert = Input.GetAxis("Vertical");
float Horz = Input.GetAxis("Horizontal");
animator.SetFloat(HorzFloat, Horz, 0, Time.deltaTime);
animator.SetFloat(VertFloat, Vert, 0, Time.deltaTime);
}
bool IsGrounded()
{
return Physics.CheckCapsule(GetComponent<Collider>().bounds.center, new Vector3(GetComponent<Collider>().bounds.center.x, GetComponent<Collider>().bounds.min.y - 0.1f, GetComponent<Collider>().bounds.center.z), 0.5f);
}