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

How to make complex Collides using boolean operations? Physics Collider Combination

Discussion in 'Physics' started by AlanMattano, Oct 28, 2016.

  1. AlanMattano

    AlanMattano

    Joined:
    Aug 22, 2013
    Posts:
    1,500
    Is it possible use a Box Collider component substract a Capsule Collider using physics?
    I wish to make a capsule with flat cups instead of making a mesh.
    As for example, I want to make a wheel using a sphere and subtracting the 2 side. Or a Colum by using a capsule and a box subtraction.
    I wish to make an if statement

    if ( CapsuleCollider && !BoxCollider ) { ...// normal physics reaction

    But I has no clue how to start. Mabe can be that in this case, the BoxCollider is a trigger that disable the CapsuleCollider. Is a draft idea but do not how to start.
     
  2. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,398
    Physics has no support for any boolean operations like that. The only way would be to use mesh colliders and do the boolean operations yourself (highly non-trivial).

    --Eric
     
  3. AlanMattano

    AlanMattano

    Joined:
    Aug 22, 2013
    Posts:
    1,500
    Thanks, @Eric5h5 . Yes,

    @MortenSkaaning How can I ask Physics to support boolean?

    If I make an expensive round custom mesh collider, is not smooth because the mesh collider is not a curve. So for making a wheel (as an example) we can use a sphere that is round. And is not possible to simulate the same using mesh colliders because the surface of the mesh are never in flat contact with the flat ground (the face orientation is always wrong) (is just an example to understand the problem [ I know there is wheel collider for that]). I mean that the sphere (or capsule) colliders are capable to do something that the mesh colliders can't do. And is, be facing the other collider. This has a role in the reaction intensity and direction (also is cheaper but is not the discussion here). So mesh colliders wheel will be always jumping (mini jump) because is not round while the sphere will not jumping. Also if I try to make the mesh colliders very dense, full of poly.
    So the only way to avoid the micro jumps and achieve smoothness is using the round collider primitives, that can be a nice improvement and opens the door to a new level of combinations.

    How can I ask Physics to support boolean?

    I think we must invent the wheel one more time (my father will not agree in this) and invent something new that gives the chance to use round collider primitives. We need to invent the way to combine the round collider primitives. For example:
    • Making a sphere as Physics collider that is enable and can be disable
    • A second sphere collider used as zone detection
    • Another collider used as zone detection to subtract and disable the first sphere collider.
    When I do it in code, do not work because if I disable the physic sphere collider the car has now no wheel. (Is just an example to understand ). So I need to sort in the detection the object and assign a specific collider for each object collision. Too much complex for my skills. The only thing I can imagine is Physics boolean support. This new physics "component" can have a combination: add, subtract or intersect.

    I show here how a physics intersect combination is used for a Physics Boolean wheel:
    • Making Physics sphere collider "wheel"
    • A second Physics box collider (wheel with) that reacts in the side
    • A Physics boolean "component" operation that makes the intersection combination. (if both are true) .
    upload_2016-10-28_13-13-8.png
     
    Last edited: Oct 28, 2016
  4. Fu11English

    Fu11English

    Joined:
    Feb 27, 2012
    Posts:
    257
    If you are looking for an alternative to the wheelcollider there's one in development here, complete with demo.

    It provides collision for a full cylindrical shape.
     
  5. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,398
    Unity uses PhysX, so you'd have to talk to nVidia about it, but it sounds too complicated to implement for real-time physics.

    --Eric
     
  6. AlanMattano

    AlanMattano

    Joined:
    Aug 22, 2013
    Posts:
    1,500
    Looks perfect, Thanks for the link. I was thinking more in bending wings and columns colliders. The wheel was a simple example to understand. But the asset can be useful to understand how is it made. Looks like it will be ready soon.