Search Unity

Physics.Raycast and Mesh Colliders

Discussion in 'Physics' started by EdgarCarrera, May 1, 2016.

  1. EdgarCarrera

    EdgarCarrera

    Joined:
    Apr 21, 2014
    Posts:
    255
    Why raycast ignore the mesh colliders?
    i have all LayerMask and no detect

    Code (CSharp):
    1. Vector3 vector2 = 0.5f * (allWheels[0].transform.position + allWheels[1].transform.position) - new Vector3(0f, 0.5f, 1f) * .5f;
    2.         RaycastHit raycastHit;
    3.         isGrounded = Physics.Raycast(vector2, -Vector3.up, out raycastHit, .5f,wheelPhysics);
    upload_2016-5-1_12-28-29.png
     
    Last edited: May 1, 2016
  2. Hyblademin

    Hyblademin

    Joined:
    Oct 14, 2013
    Posts:
    725
    So your raycast is starting in the wrong spot and only goes for 0.5f? That's why you're not getting any hits.

    Why are you multiplying your start vector components by 0.5f? I'm sure this is why it's in the wrong spot. It's possible you're looking for localPosition. Halving any position vector in world space will give you a point halfway between that point and (0,0,0).

    Also, why is it called
    vector2? Is it some second vector? That's confusing to me due to the existence of the Vector2 class; I urge you to change the name to something else for clarity.