Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

Raycast2D & edgeCollider

Discussion in 'Scripting' started by NikoBusiness, Mar 24, 2016.

  1. NikoBusiness

    NikoBusiness

    Joined:
    May 6, 2013
    Posts:
    289
    does the raycast2D detect hit of edgecollider?
    im asking because i have been trying to detect hit with raycast2d with a layermask filter but something is going wrong. the layermask that is 8th layermask, i have been trying with 1 << 8 bitmask check and with public layermask inspector check but nothing helps... plus the hit detects the ignored layermask collider ... how is that even possible?

    check here for more info : http://answers.unity3d.com/questions/1160441/raycast2d-layermask-problem-or-edgecollider.html
     
    Last edited: Mar 24, 2016
  2. GarthSmith

    GarthSmith

    Joined:
    Apr 26, 2012
    Posts:
    1,240
    I've run into this before so I know what's up. =p

    Your code from Unity Answers:
    Code (csharp):
    1. RaycastHit2D hit = Physics2D.Raycast (transform.position, Vector2.up, 1 << LayerMask.NameToLayer ("field"));
    Look closely at the third parameter on the documentation.
    http://docs.unity3d.com/ScriptReference/Physics2D.Raycast.html

    The third argument should be DISTANCE, but you are putting in a LAYERMASK.

    If you want to raycast for an infinite distance, put float.PositiveInfinity as your third argument and move the Layermask to the forth argument.
     
    Last edited: Mar 25, 2016
  3. NikoBusiness

    NikoBusiness

    Joined:
    May 6, 2013
    Posts:
    289
    you are the man!