Search Unity

EventSystem.RaycastAll does not hit 2d collider

Discussion in '2D' started by heartshapedbox, Dec 13, 2018.

  1. heartshapedbox

    heartshapedbox

    Joined:
    May 27, 2018
    Posts:
    31
    Hi. How can i detect 2d collider by EventSystem.RaycastAll ?
    It detect BoxCollider but not to BoxCollider2D.

    Thanks
     
  2. qqqbbb

    qqqbbb

    Joined:
    Jan 13, 2016
    Posts:
    113
    Use Physics2D.Linecast for 2d physics.
     
  3. RidgeWare

    RidgeWare

    Joined:
    Apr 12, 2018
    Posts:
    67
    RayCastAll is meant for unique situations where you need to know how many different colliders a ray is passing through - which can be very useful for determining partial line of sight past/through multiple targets in 2D - so LineCast isn't always the answer in 2D physics casting.

    That said, if all you need to do is detect whether a line can reach a target or not, then yes, LineCast is simpler.

    (Although, if you're properly using a RaycastHit2D[] RayCastAll(), it should still detect a BoxCollider2D)
     
    Last edited: Dec 13, 2018