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 JamesGameDev · Mar 27, 2017 at 11:32 AM · 2dcolliderstriggersontriggerenter2d

Why is my Collider Broken?

Hey Comm-Unity, I usually consider myself to be a very well-rounded and developed Unity user, however, I am having issues with a collider. What I have is a simple 2D Game, and I'm trying to make a UI Image appear when a sprite collides with another sprite. Both sprites have 2D Box Colliders, One has Is Trigger set to true, and the other has a 2D Rigidbody attached. I am using the following code:

 void OnTriggerEnter2D(Collider2D c)
 {
         if(c.tag == "Other")
         {
                  Panel.SetActive(true);
         }
 }

Can anyone think of the problem? Thank you!

  • Tiger27

Comment
Add comment · Show 5
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 TSI25 · Mar 27, 2017 at 12:27 PM 0
Share

The code itself seems pretty bullet proof. I would add a debug before the if to see if OnTriggerEnter2D gets called at all. If it does get called it might just be that the object co$$anonymous$$g in doesn't have the right tag. If it's not getting called at all then it probably has something to do with the collider or the rigidbody. Can we get a screenshot of the collider setups in the inspector?

avatar image hexagonius · Mar 27, 2017 at 01:41 PM 0
Share

How are you moving your rigidbody?

avatar image JamesGameDev hexagonius · Mar 27, 2017 at 09:18 PM 0
Share

Hey @TS125 and @hexagonius, Thanks for the quick reply. As for the if statement, I already did, and it isn't logging anything. Another thing I did was add the following code, to see if it's calling a collision ins$$anonymous$$d:

 void OnCollisionEnter2D(Collision2D c)
 {
        Debug.Log("Collision!");
 }

As for the rigidbody, I am moving it with Vector2.$$anonymous$$oveTowards (Or maybe Vector3.$$anonymous$$oveTowards, don't have my code in front of me). Does that affect anything? Thank you for your help!

  • Tiger27

avatar image hexagonius JamesGameDev · Mar 27, 2017 at 09:39 PM 0
Share

you changed it to OnCollisionEnter. Is it a collider now?
$$anonymous$$oveTowards teleports the object, which is the reason for the missing call. if the rigidbody is kinematic use $$anonymous$$ovePosition on the Rigidbody.

Show more comments

0 Replies

· Add your reply
  • Sort: 

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

106 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 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 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 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 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 avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

2D triggers not working 2 Answers

Two colliders on GameObject with only one acting as trigger 2 Answers

Why OnTriggerEnter2D is triggered on an Object which doesn't include trigger collider? 1 Answer

OnTriggerEnter2D doesn't work on collider with effector 0 Answers

Triggers (colliders?) randomly stop working 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