Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

BoxCast a specific collider

Discussion in 'Scripting' started by Phyksar, Oct 13, 2021.

  1. Phyksar

    Phyksar

    Joined:
    Jul 8, 2021
    Posts:
    1
    Hello, I'm trying to make a box cast with one specific collider. I've found an API for Collider.Raycast in docs that interacts with one collider but there's no method for BoxCast. Is there a reason that they are not implemented?

    I'm currently using a layer swapping for this but I don't feel like it's the way they are should be used.
    Code (CSharp):
    1. GameObject colliderGameObject = collider.gameObject;
    2. int colliderLayer = colliderGameObject.layer;
    3. colliderGameObject.layer = Physics.IgnoreRaycastLayer;
    4. bool boxCastHit = Physics.BoxCast(center, halfExtents, direction, out hitInfo, orientation, maxDistance, 1 << Physics.IgnoreRaycastLayer);
    5. colliderGameObject.layer = colliderLayer;
     
    InterFlash likes this.