- Home /
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:
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.
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.
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);
}
}
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.
Check the hierarchy for any invisible object you may be missing, or any collider out of place. $$anonymous$$ore than likely, it's hitting something you were unaware of.
Your answer
Follow this Question
Related Questions
BoxCollider2D is not working as expected 1 Answer
No Collision in 2d Scene 0 Answers
Bump when crossing box colliders 1 Answer
Know if there is Collisions on my boxCollider 1 Answer
I don't think I get collision box, can someone help? 0 Answers