Search Unity

Mesh colliders

Discussion in 'Getting Started' started by tawdry, Oct 21, 2015.

  1. tawdry

    tawdry

    Joined:
    Sep 3, 2014
    Posts:
    1,357
    Hi
    Why does the fps controller sometimes get stuck on mesh colliders(usually on stairs but not always). Are mesh colliders not supposed to hug the mesh.Is there a way to avoid this situation.
     
  2. Adam-Buckner

    Adam-Buckner

    Joined:
    Jun 27, 2007
    Posts:
    5,664
    Can you post some specific examples with images from the scene view?
     
  3. tawdry

    tawdry

    Joined:
    Sep 3, 2014
    Posts:
    1,357
    While on the subject of mesh colliders anyway to get them to be double sided. For instance I have single sided meshes for my houses but a mesh collider will only work for one side ie the outside allowing those inside to walk through the mesh to the outside.I know i can duplicate the geometry but really don't want to do that maybe some kind of code?
     
  4. Adam-Buckner

    Adam-Buckner

    Joined:
    Jun 27, 2007
    Posts:
    5,664
    Mesh collider are inherently inefficient and should only be used in the rarest of occasions. It is best to use a set of primitive colliders instead. See the manual on the rigidbody component and note the section on compound colliders.
     
  5. tawdry

    tawdry

    Joined:
    Sep 3, 2014
    Posts:
    1,357
    Well the mesh collider is for a very low poly house so i think with simple meshes it is ok to use(a mesh collider on a plane should be the same expense as a mesh collider on that plane wouldn't it?) and maybe even cheaper than many primitives?. Using a primitive is difficult also for rounded shapes where you need a hole in the collision area ie a door in a tower.But it is problematic when only one side has collision.
     
  6. Adam-Buckner

    Adam-Buckner

    Joined:
    Jun 27, 2007
    Posts:
    5,664
    Remember that the physics system is trying to calculate volumes and areas. The simpler the mesh, the better. It depends upon how simple your house is! But if you're holding out holes for doors and windows, it might be better to use primitives. IIRC, the primitives are optimised in the physics system.

    Do you have an example of your mesh collider? A screenshot?
     
  7. tawdry

    tawdry

    Joined:
    Sep 3, 2014
    Posts:
    1,357
    Screenshot but i don't know how to get the mesh collider to show .9 submeshes each with a mesh collider component
     

    Attached Files:

  8. tawdry

    tawdry

    Joined:
    Sep 3, 2014
    Posts:
    1,357
    Maybe this is ok?
     

    Attached Files:

  9. Adam-Buckner

    Adam-Buckner

    Joined:
    Jun 27, 2007
    Posts:
    5,664
    First off, you will need to turn oFf the mesh renderer to easily see the collided so, as they are resting in a concurrent space worth the rendered geometry. Second, are you aware of the need for convex mesh colliders?
     
  10. tawdry

    tawdry

    Joined:
    Sep 3, 2014
    Posts:
    1,357
    Convex is less expensive but it is useless when i try it creates a enormous collider around the house.
     
  11. Adam-Buckner

    Adam-Buckner

    Joined:
    Jun 27, 2007
    Posts:
    5,664
    Be aware that there are some limitations to non-convex colliders and collisions. These are some of the many reasons that compound colliders made of groups of primitives are advisable over a mesh collider. In your case, this could be fine, as your house is static geometry and I assume has no rigidbody. Just be aware that, industry wide, primitive colliders are used whenever possible.
     
  12. Adam-Buckner

    Adam-Buckner

    Joined:
    Jun 27, 2007
    Posts:
    5,664
    http://docs.unity3d.com/Manual/CollidersOverview.html
    "A collider, which is invisible, need not be the exact same shape as the object’s mesh and in fact, a rough approximation is often more efficient and indistinguishable in gameplay."

    "With careful positioning and sizing, compound colliders can often approximate the shape of an object quite well while keeping a low processor overhead. Further flexibility can be gained by having additional colliders on child objects (eg, boxes can be rotated relative to the local axes of the parent object)."
     
  13. tawdry

    tawdry

    Joined:
    Sep 3, 2014
    Posts:
    1,357
    Well i will try out this compound collider guess a buch of box colliders should do it but for round shapes i will stick with mesh collider unless there is a way to cut a opening in the primitive colliders
     
  14. Adam-Buckner

    Adam-Buckner

    Joined:
    Jun 27, 2007
    Posts:
    5,664
    Where do you have round shapes? The dormers on the roof? Will a player ever be able to get up there? If not, ignore them completely. If they can, are they able to get "under" the dormer? If not, look at capsule colliders. No one can see your colliders, so they don't have to be pretty. A box collider might work as well. No one will notice if they throw a rock and it bounces off... But not perfectly.

    For fun, go into a game you are sure uses tight mesh colliders and really fuss with the environment, and you'll discover they don't... and that you've never noticed.
     
  15. tawdry

    tawdry

    Joined:
    Sep 3, 2014
    Posts:
    1,357
    Well a tower can be round but there won't be so many of them and again simple low poly so 5 or 6 mesh colliders on towers won't make much of an impact i'm sure. Maybe instead of a square i will just make a prefab of 2 planes back toback .
     
  16. Adam-Buckner

    Adam-Buckner

    Joined:
    Jun 27, 2007
    Posts:
    5,664
    There are capsule colliders (Components/Physics /Capsule Collider). These can be very useful.
     
  17. tawdry

    tawdry

    Joined:
    Sep 3, 2014
    Posts:
    1,357
    Yes but they don't have holes in and I want doorways in and out of the tower so they are not really a viable option