Search Unity

Physics2D.Raycast doesn't ignore self collider

Discussion in '2D' started by vptb, Jul 25, 2014.

Thread Status:
Not open for further replies.
  1. vptb

    vptb

    Joined:
    Jan 15, 2014
    Posts:
    28
    I just tested it with 3D Physics and the Raycast ignores the collider on the object the raycast is casted. But when using Physics2D the ray hits the collider of the object where it is cast....

    Is this a bug? Or is there any workaround to this?
     
  2. Vitor_r

    Vitor_r

    Joined:
    May 23, 2013
    Posts:
    93
  3. vptb

    vptb

    Joined:
    Jan 15, 2014
    Posts:
    28
    Yes I am using it correctly, I tested it with a simple object with the layer "Obstacle" with a Box Collider 2D, I casted a Physics2D.Raycast with a layermask of LayerMask.GetMask("Obstacle"). And it hits himself. Can someone please try this and confirm if this is just a problem with me?
     
  4. Vitor_r

    Vitor_r

    Joined:
    May 23, 2013
    Posts:
    93
    I'm at work right now, so i can't test it for you.
    But if you post some code and screenshots i can try help you more :)


    Edit:

    I just read your first problem in the Unity Answers. http://answers.unity3d.com/questions/756380/raycast-ignore-itself.html
    And that clear things up, i dont have an answer for you now, i will think about it and come back later hehehe.
     
    Last edited: Jul 25, 2014
    CunningFox146 likes this.
  5. Vitor_r

    Vitor_r

    Joined:
    May 23, 2013
    Posts:
    93
    What about disabling the collider of the turret when the ray starts and when it hits something you enable again? Kind of hackish but could work.
     
  6. AB498

    AB498

    Joined:
    May 4, 2019
    Posts:
    17
    Probably, a bug. A big one. Request to Unity: Please Fix this :(
     
  7. LiterallyJeff

    LiterallyJeff

    Joined:
    Jan 21, 2015
    Posts:
    2,807
    Not a bug, and this thread is from 2014.

    http://answers.unity.com/answers/869966/view.html
     
    Rachan, Graph and Helladah like this.
  8. unity_V_0twZiF8yYYXw

    unity_V_0twZiF8yYYXw

    Joined:
    Jun 18, 2019
    Posts:
    3
    Rachan and LiterallyJeff like this.
  9. Jargs

    Jargs

    Joined:
    Dec 8, 2018
    Posts:
    5
    For anyone reading this in 2021, the setting appears to have been renamed. I found it under Edit > Project Settings > Physics 2D > Queries Start In Colliders.
     
    qjaxoddl522 and BenkeA like this.
  10. Graph

    Graph

    Joined:
    Jun 8, 2014
    Posts:
    154
Thread Status:
Not open for further replies.