- Home /
Why is Physics.CheckCapsule always returning true?
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);
}
Comment
Best Answer
Answer by Sejadis · Dec 15, 2015 at 02:46 PM
for everyone having that problem:
its returning true because it checks the exact position of your player capsule - so its returning true because there is something
solution:
set your player to the player layer and add the Layermask to the CheckCapsule function
Your answer