Question by
jfmaniccia · Oct 25, 2018 at 09:20 PM ·
collisionraycastfloor
Why is a raycast not setting a maxDistance
I am trying to detect if the player is touching the ground or not. I am doing this by getting the length of the collider in the y direction and shooting a ray down towards the ground. I have all the variables filled out and set to what I need them to be. But no matter what I set the maxDistance to, the length of the raycast is still infinite. I tested this by dragging the player to over 1000 unites above the floor. It Does work as intended because when there is no floor beneath the player it does return false. By this I mean I dragged the player so that the floor was no longer below the player.
//Are you on the ground
bool OnGround()
{
Vector3 origin = mTransform.position;
origin.y += 0.6f;
Vector3 dir = -Vector3.up;
float dis = contrCollider.bounds.extents.y;
RaycastHit hit;
if (Physics.Raycast(origin, dir, out hit, dis + 0.1f, ignoreForGround))
{
Debug.DrawLine(origin, dir, Color.red, dis + 0.1f);
return true;
}
return false;
}
Can anyone tell me what I did wrong. As far as I know this should be working. Thank you for your help.
Comment