Search Unity

Need help with setting up a simple collider for a model I made in Unity

Discussion in 'Getting Started' started by E2TheFom, Jul 26, 2018.

  1. E2TheFom

    E2TheFom

    Joined:
    Jul 26, 2018
    Posts:
    7
    I just started using unity, and I'm trying to add a collider to a object resembling a conference table.
    Table.PNG

    However, when I add it, the "hit box" goes straight from the top of the table down to the base without accounting for the area between the surface of the table and the supporting block under it. This is hard to explain but here is a picture of the hit box:
    Unity-table.PNG

    As you can see, when the table falls directly above the cube, it falsely triggers a collision.

    I would like to know how I can fix this. Any help will be appreciated.
     
  2. JoeStrout

    JoeStrout

    Joined:
    Jan 14, 2011
    Posts:
    9,859
    For a shape like this, just remove the MeshCollider, and instead add two BoxColliders, one for the top and one for the bottom. (You could also uncheck "Convex" on the MeshCollider, but mesh colliders have various limitations and annoyances, so box colliders are always better when you can use them.)

    Now it's my turn to ask a question: how exactly did you make this model in Unity? I didn't think it had any mesh-creation tools built in.
     
  3. E2TheFom

    E2TheFom

    Joined:
    Jul 26, 2018
    Posts:
    7
    To answer your question, I created the model within Blender. I'm not really sure what Convex exactly does, but when it's unchecked, the model falls right through the surface. Furthermore, the surface was also made in Blender, it uses a box collider, if that is of any use.

    Another more complicated example would be this:
    Capture.PNG
    When I turn off Convex, it falls through the ground
     
    Last edited: Jul 26, 2018
  4. JoeStrout

    JoeStrout

    Joined:
    Jan 14, 2011
    Posts:
    9,859
    OK, that makes sense. I thought your first post said you made this model in Unity, which surprised me. :)

    Yeah, non-convex mesh colliders are mostly useless. Stick to boxes, spheres, and capsules when you can. A convex mesh is second best. (Google the term if you really want to understand what it means.)
     
  5. E2TheFom

    E2TheFom

    Joined:
    Jul 26, 2018
    Posts:
    7
    Thank you for the advice, do you have any recommendations for more complex models like office desk shown above, for which I can't solely use basic shapes like boxes and circles?
     
  6. JoeStrout

    JoeStrout

    Joined:
    Jan 14, 2011
    Posts:
    9,859
    Actually, you probably can. Keep in mind that it doesn't have to be perfect. Game development is all about finding the good enough and pulling whatever tricks you can to increase performance. So, you don't try to capture every nook and cranny; you don't worry about the undersides of things that you never expect to matter; etc.
     
  7. E2TheFom

    E2TheFom

    Joined:
    Jul 26, 2018
    Posts:
    7
    Okay, thank you for the help!