Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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
0
Question by siddharth3322 · Apr 22, 2014 at 11:50 AM · collisionrigidbodycolliderunity4.3

Detect collider when same object contains more than on collider

At present working on 2D game. I have main character in which I have attached box collider and circle collider with rigid body component.

I want to handle collision for box collider and circle collider differently. But at present I can't able to find any way in which part of main character other obstacles are collided.

How to detect collider type in which collision happen?

Comment
Add comment · Show 1
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 maddFrogg · Apr 22, 2014 at 12:16 PM 0
Share

I'd keep one collider on the player and assign the other one to an empty game object son of the player's transform.

You will need to assign a collision detector script to each one.

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by HarshadK · Apr 22, 2014 at 12:33 PM

You can detect which collider of player has collided with the object from the collision script on the object with which player is collided.

The psuedo code is:

 void OnCollisionEnter(Collision2D col) {
     if(col.gameObject.name == "player" && col.collider == "box") {
        // Do something for box collider
     }
     else if(col.gameObject.name == "player" && col.collider == "circle") {
        // Do something for circle collider
     }
 }

You have to attach this script to the object with which the player is colliding

Comment
Add comment · Show 6 · 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 Marzoa · Oct 23, 2014 at 01:28 PM 0
Share

What if you have two circle colliders?

avatar image HarshadK · Oct 28, 2014 at 01:56 PM 0
Share

@$$anonymous$$arzoa you should not have two same type of collider on a single object. In this case you need to use a child object with second collider on it.

avatar image Marzoa · Oct 28, 2014 at 02:53 PM 1
Share

Who says that? In which Unity version? Actually I have objects with several colliders of the same type, and they work fine.

avatar image Marzoa · Oct 29, 2014 at 02:54 PM 1
Share

I am not a man of faith so, why I should not have two of the same type? It is written in any place of Unity official documentation or so?

As told, I am using them and they are working perfectly. Adding one GameObject for each collider doesn't provide any advantage and several disadvantages.

avatar image HarshadK · Oct 30, 2014 at 08:59 AM 2
Share

You can have two colliders of the same type on an object if you want but then it would require some calculations to find the exact collider that was collided. If you do not need this feature to find exact collider then you can have multiple colliders of same type on same object.

The method to have child objects was in relation to the problem at hand and not a general rule of thumb.

Show more comments

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

20 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Rigidbody stuck in colliders when moving and ricosheting. 0 Answers

OnCollisionEnter but have colliding object not move the object it collides with 1 Answer

2D:I have a movementController script on my character but it doesn't move forward 0 Answers

handling collision with two objects of the same tag 1 Answer

Collisions between two rigidbody's and scripting collisions problem 2 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