- Home /
Why is my sphere collider only reporting 1 collision in corners? (pic)
Here is a top-down view of my sphere collider pushed into a corner of my environment mesh collider. It is only reporting one collision, and that is the collision with the north wall; the angled wall is being entirely ignored.
If you continue to move the collider to the left, eventually the physics system kicks in and reports a second collision, but Unity seems to get confused and collisions with both walls will flicker on and off. Flat walls and corners with 90 degree angles work 100% of the time.
Please note that this is NOT a fast-moving rigidbody and I've tried every permutation of interpolation, collision detection, kinematic, and penetration penalty.
So, is this some sort of limitation on Unity's internal collision detection? Does it not like obtuse corners? Does it only check on fixed angles or something? Or have I not thought of something?
Thanks!
Sorry for the delay, yes it is a single enclosed mesh collider. And actually, on that point, I even added thickness to the collider mesh, as someone suggested on IRC, but it didn't do anything to improve the detection.
Answer by clunk47 · Sep 24, 2013 at 04:24 AM
If you're using OnCollisionEnter within a script attached to the sphere, that could be a problem because OnCollisionEnter only detects one collision at a time. Try using a script with each collider in your scene instead of just one on the sphere. This may not be what you're doing, but that's what it sounds like. If not, I'll remove this lol.
I was using both OnCollisionEnter and OnCollisionStay to funnel into a collision detection method that looped through all the collisions reported and did some math to push the object back. It worked beautifully on flat walls and 90 degree corners, but simply wouldn't report 2 collisions in the case posted here.
Interestingly, I've since switched to simply using vanilla rigidbodies and I've noticed that they, too freak out in this corner, so I'm thinking it's a limitation of Unity's physics implementation altogether.
Answer by haim96 · Sep 24, 2013 at 08:05 AM
@clunk47, i think he not using OnCollisionEnter. unity physics should handle the collisions but it seems it miss the wall for some reason.
@calbar, can you try use capsule colider instead of sphere? you can align it in a way it will work the same as sphere from the top. i saw somewhere that the capsule works better than the sphere to detect collisions...
Unfortunately, I ditched this approach and ins$$anonymous$$d went back to using standard rigidbodies and smoothing out their jumpy motion. Wish I would have tried this, though, cause now I'm curious! Sorry about that, but thanks for your reply.