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

Raycast2D - I just want to detect the point the ray INTERSECTS

Discussion in 'Editor & General Support' started by cloudcamaleoniv, Aug 24, 2014.

  1. cloudcamaleoniv

    cloudcamaleoniv

    Joined:
    May 17, 2013
    Posts:
    57
    So, Physics.Raycast (the 3D one) cannot detect a collider if the ray starts inside the collider.

    This is not true for the Physics2D.Raycast. If it starts inside a collider2D, it also detects this hit.

    Is it possible to make the Physics2D.Raycast behaves exactly like the 3D one?

    Thanks
     
  2. cloudcamaleoniv

    cloudcamaleoniv

    Joined:
    May 17, 2013
    Posts:
    57
    To be more clear...

    So, the first image is the Physics.Raycast behaviour. The second image is the Physics2D.Raycast behaviour.

    I want the Physics2D.Raycast to behave exactly like the Physics.Raycast, only detecting the moment the ray ENTERS a collider.
     
  3. cloudcamaleoniv

    cloudcamaleoniv

    Joined:
    May 17, 2013
    Posts:
    57
  4. hippocoder

    hippocoder

    Digital Ape

    Joined:
    Apr 11, 2010
    Posts:
    29,723
    Compare hit.point with point of object. That's what I did for our games. It's really not much maths to get the distance is it?
     
  5. cloudcamaleoniv

    cloudcamaleoniv

    Joined:
    May 17, 2013
    Posts:
    57
    In my example I've used boxes, but there's going to be lots of collision types, circles, meshes, etc, that is why I can't use this method =(