Search Unity

Help understanding all 8 collider/rigidbody combinations

Discussion in 'Physics' started by GregoryFenn, Apr 6, 2018.

  1. GregoryFenn

    GregoryFenn

    Joined:
    Feb 13, 2018
    Posts:
    43
    Can someone help me understand when my gameObject should be which of these 8 collider/rigidbody combinations. The mix between convex, trigger, rigidbody is very confusing. What I'm hoping for is a table of suitable situations for each of these 8 cases. Even an intuitive definition of "convex" "trigger" "Rigidbody" would help me!


    (1) Collider: non-convex. Rigidbody.
    (2) Collider: convex, non-trigger. RigidBody.
    (3) Collider: convex, trigger. RigidBody.
    (4) Collider: non-convex. No Rigidbody.
    (5) Collider: convex, non-trigger. No RigidBody.
    (6) Collider: convex, trigger. No RigidBody.
    (7) No Collider. Rigidbody.
    (8) No Collider. No Rigidbody.

    (You can't have a trigger collider that is non-convex.)

    Does my question get even messier if I ask which situations I should use "isKinematic" for the Rigidbody?


    I have a lot of trouble handling collisions meaningfully, and I resort to making everything a kinematic Rigidbody with a trigger collider, and programming my own physics ... which I know is bad of me. (I'm new!!)
     
    Last edited: May 20, 2018
  2. Edy

    Edy

    Joined:
    Jun 3, 2010
    Posts:
    2,510
    Quick guide:

    (2) Collider: convex, non-trigger. RigidBody.
    Things that will be moved by physics: characters, cars, ships, physically interactable parts in the scenario... Colliders must be convex so they can collide with the scenario (non-convex, see below).

    IsKinematic: when you move some of these things yourself instead of the physics, but you want other objects to physically interact with them. Example: a self closing door, which would push characters away when closing. Always move these objects with Rigidbody.MovePosition and Rigidbody.MoveRotation from FixedUpdate.

    (4) Collider: non-convex. No Rigidbody.
    Static scenario that doesn't move: ground, mountains, trees, streets, sidewalks, rooms, walls, static furniture...

    (5) Collider: convex, non-trigger. No RigidBody.
    Also for the static scenario, but the parts that may be optimized. Physics calculations are faster among convex colliders, so you may use these in specific parts of the scenario. For example, you may check convex in the collider of a building, a light post, a tree trunk, or any part that might be made convex while conserving most of its shape.

    (6) Collider: convex, trigger. No RigidBody.
    Static "detectors". Triggers just launch the OnTriggerEnter / OnTriggerLeave / OnTriggerStay events in your script when any of the moving objects (2) contacts them.This allows you to take decisions based on what's happening on the scene.

    Examples: a power-up that raises life when the player walks on it, an "escape" area the player has to reach for completing the level, a check-point in a racing game...

    (7) No Collider. Rigidbody.
    Visual objects driven by physics, but without colliding with other objects. Example: an antenna attached to a car via joint. The antenna visually moves with the inertia of the car, but doesn't collide nor interact with anything.

    (8) No Collider. No Rigidbody.
    Objects that make or show something, but they don't really interact with the other objects in the scenario. Examples: visual effects, audio effects, particle systems, dashboard...


    The other cases have rare applications, if any:

    (1) Collider: non-convex. Rigidbody.
    Not supported. A Rigidbody requires a convex collider.

    (3) Collider: convex, trigger. RigidBody.
    As said, a trigger is just a kind of "event launcher". It doesn't cause collisions. This object would be some kind of "entity" being driven by physics, but as it doesn't have collider, it would just fall down to the infinity.

    Note: you may attach trigger colliders to moving objects (2) so you could, for example, detect when some specific object contacts the player. You may have colliders and triggers in the same object. Colliders cause physical collisions, Triggers just raise events in your scripts.
     
    Last edited: Apr 7, 2018
  3. GregoryFenn

    GregoryFenn

    Joined:
    Feb 13, 2018
    Posts:
    43
    Thanks! I'll append this as a long comment to the end of a few scripts as a handy reminder ^_^ thanks!
     
    Edy likes this.
  4. Edy

    Edy

    Joined:
    Jun 3, 2010
    Posts:
    2,510
    You're welcome! Have fun!
     
  5. Edy

    Edy

    Joined:
    Jun 3, 2010
    Posts:
    2,510
    I've edited the post as I've figured out an application for the case 7, no collider with Rigidbody.
     
    BrandyStarbrite and GregoryFenn like this.
  6. GregoryFenn

    GregoryFenn

    Joined:
    Feb 13, 2018
    Posts:
    43
    Nice example :)
     
  7. mani3307

    mani3307

    Joined:
    Dec 5, 2017
    Posts:
    1
    I think convex is only for mesh collider ,am I right?
     
  8. Deeeds

    Deeeds

    Joined:
    Mar 15, 2018
    Posts:
    739
    Dear Unity Management, wherever you are and whatever you're doing: Please hire Edy, pay him well. Give him Scrivener and an illustrator to sit beside him, pencil poised, to create imagery and diagrams. Let him write the documentation and manuals for physics. Then, when he's done, perhaps have a listen to his thoughts on wheels and cars, for a better car system.
     
  9. Edy

    Edy

    Joined:
    Jun 3, 2010
    Posts:
    2,510
    The primitive colliders (sphere, box, capsule) are also convex. Mesh colliders may be convex or non-convex.
     
    GregoryFenn likes this.