# Why my raycast sometimes not working?

As you see in picture, i cast rays to (vector3.right * direction) from center of boxCollider's bounds. It can detect the wall mostly, but sometimes it can't detect the wall and pass through it. the layer of wall is 'obstacle' and ray only detect that layerMask. why this happend?

            moveAmount.x = input.x * speed;
moveAmount.z = input.z * speed;

directionX = Mathf.Sign(moveAmount.x);
rayLength = Mathf.Abs(moveAmount.x) + .015f;

if (Physics.Raycast(rayOrigin, Vector3.right * directionX, out raycastHit, rayLength, collisionMask))
{
Debug.Log("Hit");
}

• First debugging steps: does anything change if you omit the rayLength and collisionMask arguments? Jun 13 '20 at 2:54
• yes. i think adjust raylength is sole solution. thanks.
– Hree
Jun 13 '20 at 8:32