Search Unity

Finding the normal of a line segment belonging to a Polygon Collider 2D.

Discussion in 'Physics' started by janimator, Dec 8, 2014.

  1. janimator

    janimator

    Joined:
    Apr 5, 2013
    Posts:
    52
    I'm trying to figure out if there is a way to return the normal of a line segment belonging to a PolygonCollider2D.
    So i know that you can only return points(vertices) of a polygon collider, but provided that I have 2 points to represent a line segment, Is there a way for me to find out which direction relative to the line segment points away from the collision area?.
     
  2. janimator

    janimator

    Joined:
    Apr 5, 2013
    Posts:
    52
    Just to update. I have looked thoroughly, and at this point I came to the conclusion that as far as I know, it is not possible to find the 'normal' (so to speak) of any of the collision points created. I've tried even just looping through the triangular collision shapes created(which I was not able to even reference) in order to find the relativity of the collision points to their respective shapes.
    Not sure what the reasoning would be to leave out this data as it is very useful.
     
  3. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    Maybe you could raycast, since a RaycastHit2D contains the normal. Aside from that, the normal is perpendicular to the line, so you can get the line from 2 points and the normal is perpendicular to that. The only question is which side of the line to use; if you know ahead of time which of the paths is the outer and which is the inner, then that's pretty trivial.

    --Eric
     
  4. janimator

    janimator

    Joined:
    Apr 5, 2013
    Posts:
    52
    Yes it seems that's the path i will need to take(no pun intended). Was curious if there was a more integrated way.