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. Dismiss Notice

Die with mesh collider

Discussion in 'Physics' started by RotemAV, Aug 9, 2015.

  1. RotemAV

    RotemAV

    Joined:
    Apr 1, 2015
    Posts:
    6
    hi
    i have created a 3d die (d8) model in Blender,
    i want do detect witch side (or face) is up,i also added a mesh collider to the game object, so i am using a ray cast like so


    Code (CSharp):
    1. ray = new Ray((transform.position + new Vector3(0, 15, 0)), -Vector3.up);
    2.         //ray = new Ray(transform.position, ts.position);
    3.         RaycastHit hit;
    4.  
    5.         if (Physics.Raycast(ray, out hit))
    6.         {
    7.             if (hit.transform.tag != "die")
    8.             {
    9.              
    10.                 return;
    11.             }
    12.            
    13.             Debug.DrawLine(ray.origin, hit.point,Color.black);
    14.             Debug.Log(hit.triangleIndex + "  hit.textureCoord=" + hit.textureCoord);
    15.             Debug.Log(hit.transform.tag);
    16.  
    17.         }
    this is working fine, but when i add a rigidbody and mark the mesh collider as Convex i get
    hit.triangleIndex=-1
    hit.textureCoord=(0,0,0)

    can some one explain to me way?
    and how i can over come this problem?
     
  2. gorbit99

    gorbit99

    Joined:
    Jul 14, 2015
    Posts:
    1,350
    You mean a dice?
     
  3. RotemAV

    RotemAV

    Joined:
    Apr 1, 2015
    Posts:
    6
  4. DarthDisembowel

    DarthDisembowel

    Joined:
    Jun 11, 2014
    Posts:
    54
    RaycastHit.textureCoord doesn't work if the meshcollider is set to convex. Which sucks when you are trying to detect the texture on a physics object, since you can't use non-convex colliders in that case.