Search Unity

Linecast not work when are dectected other collisions ?

Discussion in 'Scripting' started by FraMarSaMi, Nov 25, 2014.

  1. FraMarSaMi

    FraMarSaMi

    Joined:
    May 13, 2014
    Posts:
    86
    I have this code for to know if the character is running on gGround layer
    Code (CSharp):
    1. Physics2D.Linecast(transform.position,contact.position,1<<LayerMask.NameToLayer("Ground"));
    but it not work when the character runs over an oblique object (like into the image below). I think that the problem are the others two character's colliders because if I delete they the linecat detect when the character is on Ground layer.



    How can I solve this problem ? I can't delete the others two colliders...
     
  2. hpjohn

    hpjohn

    Joined:
    Aug 14, 2012
    Posts:
    2,190
  3. FraMarSaMi

    FraMarSaMi

    Joined:
    May 13, 2014
    Posts:
    86
  4. FraMarSaMi

    FraMarSaMi

    Joined:
    May 13, 2014
    Posts:
    86
    Anyone can help me ?
     
  5. Ricks

    Ricks

    Joined:
    Jun 17, 2010
    Posts:
    650
    The linecast goes from the middle of the player to the middle of the contact object. Therefore if hits the collider of the contact object first before reaching the middle of the contact object. Since you are casting on a specific layer it should not hit the collider of the contact object - but it still does. So the only error I can imagine is, that your player/foot object is in the same layer as the ground. This must not be!