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

Rigidbody2d blocking Colliders from being Raycasted somehow

Discussion in '2D' started by vongsawat, Jan 19, 2020.

  1. vongsawat

    vongsawat

    Joined:
    Mar 26, 2014
    Posts:
    7
    I've been using Physics2d.Raycast to detect Polygon Collider 2D with no problems so far.
    But if I add a Rigidbody2d to said gameobject or its parents, my Raycasts no longer detects the Collider.

    The Rigidbody2d is kinematic and not simulated, but I've tried it with various settings to no avail. The moment I remove the RIgidbody2d component, everything works again.

    I'm was under the impression that Rigidbody2d shouldn't affect Raycasting at all.. but so lost now.
    How to have both Rigidbody2d and still be able to detect its Colliders with Raycast?..

    For additional context, I only want to use Rigidbody2d to essentially group child/grandchild Colliders in to a Compound Collider. If there are workarounds to sidestep this whole issue, I'm all ears as well. Still hoping its just a noob mistake and not some kind of niche bug..
     
  2. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    11,315
    When you say "Not Simulated", do you mean you turned off Rigidbody2D.Simulated?

    If so then if you read the docs you'll see, "When not simulated, any attached Collider2D or Joint2D also do not participate in the physics simulation.". Raycasts won't see them because they are no longer in the simulation.
     
  3. vongsawat

    vongsawat

    Joined:
    Mar 26, 2014
    Posts:
    7
    urgh, knew it was going to be something small I'd overlooked somewhere *facepalm*

    Yes that was it exactly. Somehow overlooked the fact that Physics2d.Raycast would obviously be part of the mentioned physics simulation. Thanks for the speedy reply!
     
    MelvMay likes this.
  4. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    11,315
    No problem, good luck with your project.