• 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
Question by imaethan · Oct 19, 2014 at 05:27 PM · collisionboxcolliderboxcollider2d

BoxCollider2D error

So I've ran into a problem today with how my character attacks. Basically when you attack the box collider turns on for a certain amount of time. The problem is that the enemy gets destroyed even if it doesn't hit the collider. For some reason it can collide when it's above the box collider. Shown in this gif: alt text

The bat can be seen floating above the box collider I have selected yet it still destroys. The bat has a small box collider attached which doesn't come in contact with the selected box collider at all.

The enemy can also somehow hit the player when the colliders aren't touching.

alt text

Comment

People who like this

0 Show 0
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

1 Reply

· Add your reply
  • Sort: 
avatar image

Answer by Bloodyem · Oct 19, 2014 at 07:12 PM

It's very hard to answer without seeing the code, and I don't know what you are writing this in, but it is definitely hitting something. Try using Debug.Log to find out what.

Debug.log(col.name);

Where I wrote "col", put whatever variable you are using for the collision. Then, watch. The debug bar will tell you the name of the object it's hitting.

Comment

People who like this

0 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 imaethan · Oct 19, 2014 at 07:50 PM 0
Share

Well this is the script on the bat.

 function Update () {
 
 }
 
 function OnCollisionEnter2D (other : Collision2D) {
 
 Debug.log(other.name);
 
 if (other.gameObject.tag == "catfoodthrown") {
             
         Destroy(this.gameObject);
         
         }
 
 
 if (other.gameObject.tag == "sword") {
             
         Destroy(this.gameObject);
         
         }
 
 
 }
 
avatar image imaethan · Oct 19, 2014 at 07:54 PM 0
Share

Okay I added the debug.log command to my collision script and it's saying the bat01 collider is hitting my player. But the colliders never collide. It's always above it.

avatar image Bloodyem · Oct 19, 2014 at 09:00 PM 0
Share

Check the hierarchy for any invisible object you may be missing, or any collider out of place. More than likely, it's hitting something you were unaware of.

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.

Update about the future of Unity Answers

Unity Answers content will be migrated to a new Community platform and we are aiming to launch a public beta later in June. Please note, we are aiming to set Unity Answers to read-only mode on the 31st of May in order to prepare for the final data migration.

For more information, please read our full announcement.

Follow this Question

Answers Answers and Comments

28 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

Related Questions

No Collision in 2d Scene 0 Answers

BoxCollider2D is not working as expected 1 Answer

Easy Way To Enable A Certain BoxCollider2D? 0 Answers

Collision not detecting between two instantiated objects 1 Answer

Boxcoliders can't connect 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