Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.

Bug CastRay hitting wrong collisionfilters

Discussion in 'Physics for ECS' started by calabi, Nov 11, 2022.

  1. calabi

    calabi

    Joined:
    Oct 29, 2009
    Posts:
    230
    I have this weird problem that I'm not sure if its a bug or I'm misunderstanding something or maybe its a known bug.

    I have a CastRay with its own specific collision filter, I have it set to only hit one one specific type of object and yet it returns objects that aren't set to it nor are they set to it.

    I have several Physicsshapes inside or above one another and the one I want it to hit is the one in the middle but it keeps hitting the ones surrounding it first even though they don't reference the CastRay collision filter at all. I'm not sure if I'm explaining well enough but I can post more details later if needed just curious if anyone else has encountered this before where raycasts return objects that arent in the filters.
     
  2. WAYN_Games

    WAYN_Games

    Joined:
    Mar 16, 2019
    Posts:
    892
    From what I know the colliders in the same hierarchy are merged into a single compound collider.
    I think all layers are merged also.
    In addition to the collision layer there a collider key. Maybe you can use that to filter you cast.
     
    JosepMariaPujol and calabi like this.
  3. calabi

    calabi

    Joined:
    Oct 29, 2009
    Posts:
    230
    Thanks, I guess that makes it a bit more complicated. I did look at the collider key but couldn't figure out how to use it, but I guess I can just use component tags to identify the correct object, its just weird how it works.