Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 11 Next capture
2021 2022 2023
1 capture
11 Jun 22 - 11 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
2
Question by AdamLazaruso · Aug 10, 2015 at 09:24 AM · android2dcolliderstriggers

Two colliders on GameObject with only one acting as trigger

I'm making a 2D Android game and I need two colliders on each object.

One is a box collider that's a little bigger than the sprite to act as a hit box and detect whether the user has touched the object. It needs to be a little bigger than the sprite so that the touch will still be recognised if the user touches a little bit outside the object.

The other is a polygon collider that matches the shape of the sprite - I want this to act as a trigger to use with the OnTriggerEnter method.

The problem is that both colliders are acting as a trigger and activating the OnTriggerEnter method, which means the method is running when another object comes close to the object since the Box Collider is bigger than the sprite.

I've unticked the 'Is Trigger' box on the Box Collider but it hasn't helped.

Is there a way to have two colliders on on object but only have one act as a trigger? Does anyone have any other suggestions as to how to solve this problem?

Comment
Add comment · Show 2
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Hexer · Aug 10, 2015 at 09:39 AM 2
Share

Add a child to the parent object, attach a collider to the child. This way you actually have 2 colliders on 1 object/area, which you can move as 1 entity.

When having 2 colliders that overlap eachother it is recommended to change the physics layer of one of them and change the transform.position.z of one of them.

The touch collider should be above the other colliders in 3dSpace.

avatar image AdamLazaruso · Aug 10, 2015 at 09:53 AM 0
Share

Thought this worked but still the same problem! I'll explain in full:

I have an object called 'Ball' and this object has the polygon collider and the script with the OnTriggerEnter method.

Ball has a child object carrying the box collider with a script called 'hitbox' which references the parent object (transform.parent.gameObject) so it can do stuff when it detects a hit. The script has no OnTriggerEnter method.

But for some reason the trigger still activates when two box collider is entered! The script on the parent object doesn't reference the child or its collider at all but its OnTriggerEnter method is still picking up the collider on the child object.

2 Replies

· Add your reply
  • Sort: 
avatar image
6
Best Answer

Answer by Tkrain42 · Aug 11, 2015 at 01:32 PM

Put the hitbox child object on a different layer than the ball object. Make sure in the Edit|Preferences|Physics2D that the collision matrix has the hitbox child object's layer NOT colliding with the layer of the objects you want the polygon collider to trigger.

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image AdamLazaruso · Aug 11, 2015 at 01:54 PM 1
Share

Wonderful, thank you.

avatar image
1

Answer by Youri1er · Aug 10, 2015 at 09:27 AM

Sorry but for me it's impossible. but there is a simple way to get around your problem.

Put your polygon collider on your sprite and put your the collider on a child of your sprite. So you need a second script on your child. But it's easy if you use a reference of that script in your first script.

Comment
Add comment · Show 3 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image AdamLazaruso · Aug 10, 2015 at 09:53 AM 0
Share

Thought this worked but still the same problem! I'll explain in full:

I have an object called 'Ball' and this object has the polygon collider and the script with the OnTriggerEnter method.

Ball has a child object carrying the box collider with a script called 'hitbox' which references the parent object (transform.parent.gameObject) so it can do stuff when it detects a hit. The script has no OnTriggerEnter method.

But for some reason the trigger still activates when two box collider is entered! The script on the parent object doesn't reference the child or its collider at all but its OnTriggerEnter method is still picking up the collider on the child object.

avatar image Youri1er · Aug 10, 2015 at 12:45 PM 0
Share

In the script of the parent make a test to ignore children.

 void OnTriggerEnter(Collider other)
 { 
     if(other.tag != "Child_HitBox")
     {
        Something happen here !
     }
 }
avatar image AdamLazaruso · Aug 10, 2015 at 03:06 PM 0
Share

Nope! Still no luck with that.

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

Why is my Collider Broken? 0 Answers

[Unity 4.6.1] Weird bug between 2 Colliders 1 Answer

number of colliders inside a trigger. 2 Answers

Transform.localPosition Script Problem. 3 Answers

Bad piggies-like inventory? 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges