Search Unity

  1. Good news ✨ We have more Unite Now videos available for you to watch on-demand! Come check them out and ask our experts any questions!
    Dismiss Notice
  2. Ever participated in one our Game Jams? Want pointers on your project? Our Evangelists will be available on Friday to give feedback. Come share your games with us!
    Dismiss Notice

Need a different collider for clicking on a unit.

Discussion in 'Scripting' started by Napoleonite, Jun 27, 2015.

  1. Napoleonite

    Napoleonite

    Joined:
    Mar 15, 2015
    Posts:
    27
    I have a box collider at the feet of an enemy. But now when I want the user to click on the enemy to attack it, the user must click on it's feet... That's no good.

    So I attempted to add another collider that is like an AABB around the entire enemy, purely and only for the mouse-clicks. Not for any other collision detection. But that doesn't seem to be possible. I can't have 2 box colliders on one object. And even if I were to have 2 different colliders, the AABB would still collide with terrain and such as well...

    I could probably attach a child-object with it's own collision box to the enemy and put that on a different layer with no collision with other layers (purely for ray-casting from the mouse). But this solution seems a bit weird.

    How is this normally implemented?
     
  2. Duugu

    Duugu

    Joined:
    May 23, 2015
    Posts:
    241
    Of course you can have multiple box colliders. Just click "Add Component" > Physics > Box Collider
    Enable the "Is Trigger" option to have the new collider ignored by the physics engine.
     
  3. Napoleonite

    Napoleonite

    Joined:
    Mar 15, 2015
    Posts:
    27
    You are right.. No idea what I did wrong the first time but I do feel pretty stupid :confused:. Thanks.
     
  4. Duugu

    Duugu

    Joined:
    May 23, 2015
    Posts:
    241
    I bet almost everyone in here has experienced that feeling someday. ;D
     
unityunity