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");
}