Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 Desert-Tiger-Games · Jul 01, 2016 at 06:31 PM · 2d2d game2d-platformer2d-physicspolygon collider 2d

Two Polygon2D Collider do not Collide with Each Other (Solved)

I am making a game where objects fall from the up side to bottom and my character will collect them when they touch it. Both objects and character have polygon collider. Update "Also both have rigidbody2D"

The thing is the collision is working fine, objects can hit to my character. The problem is I can not use this collision in my code.

 void OnCollisionEnter2D(Collision2D col){
 
         if(col.gameObject.name == "character"){
             caughtByCharacter ();
         }
 
     }
 
     void OnTriggerEnter2D(Collider2D col){
         
         if(col.gameObject.name == "character"){
             caughtByCharacter ();
         }
 
     }

Both of the collision and trigger does not work. What is the problem? Is it because of polygon collider's rules?

**Thanks for all replies. When tanoshimi mentioned the character name I figure out my problem. Actually it is not about the gameobject name. Something happened because of my carelessness.

I have wrote that collision code inside the spawner not the objects falling. Sorry for bothering you all with it.**

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 EDevJogos · Jul 01, 2016 at 10:14 PM 1
Share

It could be so many things:

  • A Debug outside the if statement Works ?

  • Is the script on the same object as the collider and rigidbody?

  • Check the object name, is it realy "character".

  • Have you tried with tags ?

  • In what speed this objects colide ? if its too fast, try to set interpolate.

avatar image Desert-Tiger-Games EDevJogos · Jul 02, 2016 at 09:03 AM 0
Share

Thanks for reply. I have solved the problem you can check my reply at tanoshimi's answer.

2 Replies

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

Answer by Desert-Tiger-Games · Jul 02, 2016 at 02:42 PM

Thanks for all replies. When tanoshimi mentioned the character name I figure out my problem. Actually it is not about the gameobject name. Something happened because of my carelessness.

I have wrote that collision code inside the spawner not the objects falling.

Comment
Add comment · 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
1

Answer by tanoshimi · Jul 01, 2016 at 06:35 PM

Collisions won't be registered unless at least one of the colliding objects has a rigidbody2d component.

Comment
Add comment · Show 4 · 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 Desert-Tiger-Games · Jul 01, 2016 at 08:46 PM 0
Share

Thanks for reply. Both of my objects and character have rigidbody2D.

avatar image tanoshimi Desert-Tiger-Games · Jul 01, 2016 at 10:16 PM 1
Share

And are they called "character"?. When debugging collision (or any callback) functions not working as expected, always start by placing a Debug.Log immediately inside the method to see whether it even gets called:

  void OnCollisionEnter2D(Collision2D col){
    Debug.Log(gameObject.name + " collided with " + col.gameObject.name); 
  }
 
  void OnTriggerEnter2D(Collider2D col){
    Debug.Log(gameObject.name + " triggered " + col.gameObject.name); 
  }
avatar image Desert-Tiger-Games tanoshimi · Jul 02, 2016 at 09:02 AM 0
Share

Thanks for reply. When you mention the character name I figure out my problem. Actually it is not about the gameobject name. Something happened because of my carelessness.

I have wrote that collision code inside the spawner not the objects falling.

avatar image starrtennis · Aug 28, 2019 at 04:32 AM 0
Share

Why? That's totally ridiculous.

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

How to make slider joint immovable by the player 1 Answer

My ground checker only works... sometimes 1 Answer

simulate gravity in a 2D game 3 Answers

How do I stop my sprite from jumping in the air? 1 Answer

How to check if an object hits the ground hard enough then add explosive force around it (2D) 1 Answer


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