0
\$\begingroup\$

enter image description here

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");
            }
\$\endgroup\$
2
  • \$\begingroup\$ First debugging steps: does anything change if you omit the rayLength and collisionMask arguments? \$\endgroup\$
    – DMGregory
    Jun 13 '20 at 2:54
  • \$\begingroup\$ yes. i think adjust raylength is sole solution. thanks. \$\endgroup\$
    – Hree
    Jun 13 '20 at 8:32
1
\$\begingroup\$

In this case, adjust rayLength will be a solution. if rayLength is too short, it will raycast inside of wall at next frame.

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.