• 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 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
Add comment
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
0

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
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 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.

Welcome to Unity Answers

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.



Follow this Question

Answers Answers and Comments

29 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

Related Questions

No Collision in 2d Scene 0 Answers

BoxCollider2D is not working as expected 1 Answer

Box Colider not working properly 1 Answer

Box collider (with Rigidbody attached) gets stuck into another Box Collider 0 Answers

Rigid body not colliding with box collider. 1 Answer

  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges