- Home /
onCollisionEnter reporting wrong collider?
I have a character with a wrecking-ball type thing. It doesn't swing, it just extends forward when spacebar is pressed (more like a punching mechanism). This wrecking-ball has its own sphere collider, but the character it's attached to has a box collider. When the ball is not extended, it's contained entirely in the box collider. When it is extended, it's completely outside of the box collider.
Now, the sphere collides just fine. It pushes other rigidbodies away and it behaves as expected. BUT when I use onCollisionEnter on the enemy characters, they always report that they're colliding with the BOX collider and not with the SPHERE collider, even though I can clearly see they're not touching the box at all, they're touching the sphere. (And I know this is the box of my player because I logged the tag. )
How do I separately detect collisions with the box and the sphere, since I want two different things to happen?
Is it because the sphere doesn't have its own rigidbody? If so, how do I give it its own rigidbody without having the two rigidbodies of the ball and the player collide when the ball is not extended?
I think it might have something to do with the object hierarchy, which looks like this:
-player with rigidbody
-->null object with box collider
-->wrecking ball with sphere collider
-enemy with rigidbody and detection script
-->null object with box collider
Thank you!
@$$anonymous$$GB Unfortunately I don't have the code for this anymore so I can't check, but I think I gave the wrecking ball its own rigidbody and it didn't have any of the problems i expected it to have. Don't hold me on that though...if that's not the answer then I didn't find a fix. Sorry! =/
Have you tried putting them them on different layers and using Layer$$anonymous$$asks to interact/not-interact with objects on the different layers?
@rvinluan thanks for the reply, the collision system seems to be a bit flaky in places...
@getyour411 It appears to be reporting collisions with the wrong part of a compound collider - I still want the objects to collide normally, so don't want special layer cases.
Just try adding a separate control script with OnCollisionEnter() on the wrecking-ball.
You will be able to detect collisions separately.
Your answer
