Search Unity

  1. We are migrating the Unity Forums to Unity Discussions by the end of July. Read our announcement for more information and let us know if you have any questions.
    Dismiss Notice
  2. Dismiss Notice

Raycast 2D polygon collider not working?

Discussion in 'Physics' started by crusty210, Feb 21, 2015.

  1. crusty210

    crusty210

    Joined:
    Jul 29, 2014
    Posts:
    14
    Code (csharp):
    1. Collider2D lineOfSightEnemy = Physics2D.Raycast(transform.position, currentSelectedEnemy.gameObject.transform.position, Mathf.Infinity, enemyLayer.value).collider;
    I have the above piece of code in my project. I have noticed that it returns a collider only if gameobjects have BoxCollider2D. It returns null when it has any other type of collider (polygon2d, circle2d etc).
     
  2. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    11,704
    I have never seen that happen, not even sure how it could because behind the scenes, a BoxCollider2D and a PolygonCollider2D is the same thing i.e. a Box2D polygon.