- Home /
Colliders 2d apparently touch each other even if they should not.
Hi everyone, i'd like to ask you about a problem i ran into, relating to colliders. The title is explanatory... reminder: we're talking about physics and collider 2D (the new tools).
The attached image shows in the bottom part, the Player colliders (typical sphere for the feet and rectangle for the body) and a Ground on the left. The Ground has two colliders: one of the Ground shape (with some material and friction) and a outer one just on the edge ( small rectangle with no friction). This is done for preventing the player to stuck on the ground side if some force is applied (during movement while falling for example).
If you look at the bottom part of the image, you may notice that the player collider got stuck...bringing the character to the edge and letting him fall MAY after some attempts results in this scenario. You can't still notice, but the sphere, if you zoom in, isn't really touching anything.
In fact looking at the image above, I've removed at runtime the sphere collider and discover that the collider causing the block is the rectangular one. As you may notice it's not touching anything, nor any input is given at this point. I use a simple script (inspired by the last unity 2d lesson) for player control, and collision detection. Anyway this should be irrelevant.
So summing up:
1) Seems that an external collider (the circle) does not cover the inner one (the rectangular) as intuitively expected. It seems that the rectangular collider got stucked by himself.
2) Also...the colliders aren't touching, but the player's one is still on the air. Is this a gui problem?
Any help would be really appreciated... Thank you in advance :)
I've been running into this same issue myself. Specifically the top image. I haven't had a chance to do much troubleshooting, but it's definitely been causing issues in new platformer project.
$$anonymous$$y character will stand next to a wall, jump straight up, and stay on top of the corner exactly as illustrated in the first image.
I'm trying to verify if the colliders really are touching. So I did some calculation and checked their position, the transform position on x axis of ground (expecially the external collider) and pg, being sure it would be the absolute one for both (no nested objects). I apply the scale the character has, 0.2, to the radius of the circle and rectangle colliders. Ultimately...I hope to have made no mistakes...if this would be true...pg and ground colliders aren't touching on x axis (nor circle nor rectangle ones). Ther's a short haul between them...as expected (about 0.0277432 in the instance I checked).
I'm quite in a whirl O_o...
$$anonymous$$ay this be a scale problem?
This seems to be happening even with box colliders too. I can't just use prefabs squares each with their own collider, or else my player will often get stuck at the edges, even if the colliders overlap eachother. Have to manually lay out one long collider wherever needed =/
In fact this is a box colliders issue :( I think it's just about colliders in general, but that rectangular ones bring this problem march, stand up and be counted more easily...
I bumped into a thread that a friend pointed out to me...it mades me thinking about one simple question...
how unity manages its colliders? how it detects if 2 colliders are nearby and/or touching? (let's restrict to the 2d ones)
In fact ther's a $$anonymous$$imum distance between colliders which will be inevitably left free. I'm led to believe that overlapping of edges may result in loss of detection varying on which technique is used. If a native colliders raycast method is used, the scenario may get more difficult to comprehend. Let's not forget also that the stuck is a consequence of the fixed angle option...otherwise the object would have rotate, pivoting on the edge, and fall away.
Answer by Invertex · Jan 18, 2014 at 10:38 AM
Well, I found out the answer to this. The issue is that while the first collider you're on decides that you should be pushed out of it upwards, the collider you start going over next sees that you're more on side of it then the top and decides the shortest path to push you out of the collider is backwards, so you get stopped. The solution seems to be to use Edge colliders to build your surface instead. Make your cube out of them and it seems to work perfectly! (plus you can then define the sides as the Wall layer and the top as the Ground, simplifying level design even more.
MelvMay pointed it out in this thread:
Including a useful link about the issue.
Seems like you hit it on the nail :)
Intuitively i would expect to see the object pushed up and left from the scenario you've described. But probably this is due from a slightly different situation:
one force (left) is applied to circle collider, and the other (up) to the rectangular one. The result is trying to separate two collider which cannot in fact be separated...
the other option would be: two pushes in different axis on a same collider simply result in a stuck.
Sure as hell is that the object keeps on being stuck even after removing the touching collider...and that's weird XD
Thank you very much :) :)
Answer by gianluca8824 · Jan 14, 2014 at 10:05 PM
Take a look at Physics Manager on Project Settings: in particular try to ajust Min Penetration For Penalty and Solver Iteration Count
http://docs.unity3d.com/Documentation/Components/class-PhysicsManager.html
Let me know!
Tried it, unfortunately doesn't work. That Physics panel is only for 3D colliders, not the new 2D colliders. The new Physics2D settings only come with 2 options which are Velocity and Position Iteration count, and don't seem to affect the issue at all really.