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

[SOLVED] How to make the mesh collider of child GameObject activate a trigger.

Discussion in 'Physics' started by benleedy, Sep 6, 2020.

  1. benleedy

    benleedy

    Joined:
    Aug 29, 2012
    Posts:
    7
    I have a pickup and a player rocket. If I place a rigidbody and collider at the parent level of the player rocket, no problem, it works. However, I want the collider to be a mesh collider to match the geometry of the rocket. Problem is, I don't know how to apply those mesh colliders at the same level as the rigidbody of the parent. The child objects are made with ProBuilder and when I try to copy components after adding mesh colliders to the parent object, the shapes are all wrong. Am I stuck just making a shape out of box colliders or is there a solution I'm missing?

    [SOLUTION] If your code for OnTriggerEnter checks a collider tag, the actual game object with the collider needs the tag. It won't trigger even if the parent game object with the rigidbody has the necessary tag. Thanks, streetwalker, for helping me with that.
     
    Last edited: Sep 6, 2020
  2. Gordon_G

    Gordon_G

    Joined:
    Jun 4, 2013
    Posts:
    358
    All colliders on a gameobject and its child objects are essentially seen as one composite collider to the parent Rigidbody component. OnCollisionEnter will fire whether the collision occurs on a parent collider or a child collider. So, what exactly is not working?
     
  3. benleedy

    benleedy

    Joined:
    Aug 29, 2012
    Posts:
    7
    Sorry, I'm using OnTriggerEnter. I have no problem colliding with obstacles, but when I try to get a pickup it isn't triggering, I'm just going straight through.
     
  4. Gordon_G

    Gordon_G

    Joined:
    Jun 4, 2013
    Posts:
    358
    Yes, sorry, I realized you are using OnTriggerEnter after I posted that. But the rules are the same and there is no need to try to move the collider to the parent.

    There could be a lot of reasons why a collider marked as isTrigger doesn't fire off an OnTriggerEnter event. Are you sure you are meeting all the basic requirements for OnTriggerEnter to fire?
     
  5. Gordon_G

    Gordon_G

    Joined:
    Jun 4, 2013
    Posts:
    358
    Would be better if you show us your OnTriggerEnter code. Did you put a Debug.Log at the first line of the function? It could be the trigger is firing but something in the function is not working as you expect.
     
  6. benleedy

    benleedy

    Joined:
    Aug 29, 2012
    Posts:
    7
    upload_2020-9-6_11-31-16.png
    The Rigidbody level was tagged as "Player" but the collider was not. I changed this and now it works. Thanks for helping me work through this, I was getting pretty frustrated.
     
    Gordon_G likes this.
  7. Gordon_G

    Gordon_G

    Joined:
    Jun 4, 2013
    Posts:
    358
    glad to hear it!