Search Unity

  1. Unity 6 Preview is now available. To find out what's new, have a look at our Unity 6 Preview blog post.
    Dismiss Notice
  2. Unity is excited to announce that we will be collaborating with TheXPlace for a summer game jam from June 13 - June 19. Learn more.
    Dismiss Notice

Compound Colliders How?

Discussion in 'Scripting' started by jkreijkamp, Aug 21, 2008.

  1. jkreijkamp

    jkreijkamp

    Joined:
    Dec 5, 2007
    Posts:
    129
    Somehow I don't get compound (trigger) colliders to work as I would expect:

    I've got an object appelboom with rigidbody set to kinetic, a script that watches triggers and two child objects (kruin and stam), both child objects have box colliders with isTrigger=true.
    I would expect the script in appelboom to be triggered if something crosses the collider in kruin or stam, but it doesn't. Am I missing something?

    Thanks in advance,
    Jaap
     
  2. jkreijkamp

    jkreijkamp

    Joined:
    Dec 5, 2007
    Posts:
    129
    To demo the problem here a very simple unity project, a ball dropping on a box which has a child object with the (trigger) collider. The box has the script that I hoped would get the message.

    From the forums and the docs (although the latter is not really clear on this) what I do is how you make a compound collider (only normally with more than 1 child probably). Don't want to have a script in every child (for complex compound collider that would give quite a lot of active scripts).

    (a completely unrelated question, what do you need to include in a zip when distributing unity source? Only Assets or must Library and Temp be included as well?)
     

    Attached Files:

  3. jkreijkamp

    jkreijkamp

    Joined:
    Dec 5, 2007
    Posts:
    129
    Can't anybody help me? Please, it's kinda blocking for me and I assume this is something others have tackled before me. Again, thanks in advance.

    In case you're wondering what I'm needing it for is, I'm building a garden game and you can place objects (plants, trees, ...) in the garden, besides standard rules like an apple tree needs 3x3 tiles I also want to check if the colliders of the object run into colliders of other objects in the garden. As some trees have quite many colliders I don't want to have to add a script to every collider. You can see the current state of the project at http://ctrl-j.com.au/pages/vogelspot.html mind that the collider stuff is turned off at the moment and it's very early in development (lots of assets are placeholders from earlier game).
     
  4. Daniel_Brauer

    Daniel_Brauer

    Unity Technologies

    Joined:
    Aug 11, 2006
    Posts:
    3,355
    Hi jkreijkamp,

    I checked out your project, and the problem is that compound colliders only work for non-trigger colliders. This isn't made clear by the documentation, so I can see why you tried your approach.

    In your situation, the solution is unfortunately to have a script on every trigger in an object. While it might be annoying to attach all these scripts (although using prefabs should make it less annoying), rest assured it will not put any extra strain on Unity, as OnTriggerEnter() is only called when something enters a trigger. There is little or no overhead from having scripts attached to things if their functions do not get called.
     
  5. jkreijkamp

    jkreijkamp

    Joined:
    Dec 5, 2007
    Posts:
    129
    Thanks Muriac!

    I guess I'll have the scripts attached automatically by enumerating all kids with colliders. Luckily only the 'dummy' instance used for feedback while placing an object needs those scripts, because with the current design they easily have about 30+ colliders each. I need fairly many colliders because they're also used to measure the distance from the centre of the camera in foto-camera mode, that use DoF. If there's another way to measure distance to an object on screen without colliders (you can't read back the Z-buffer, can you?) I would love to hear ;-)

    For now, at least, I know what the problem is (it's not me missing something obvious but just normal, not so well documented, behaviour), so can make a working solution ;-)