- Home /
2D Collider aren't exact?
I have a character with a Rigidbody2D and I am moving him in the FixedUpdate method by adding forces. Yet it seems that he sometimes get stuck on a "ledge" were technically no ledge is. He has a BoxCollider2D as well a the ground.
You can clearly see the collider aren't touching yet the physics engine leaves him stuck there! The ground boxes are perfectly aligned via vertex snapping and the character started a bit above the ground to prevent him from going inside there.
What can I do to prevent this from happening? I mean sure I could implement a jump, but who would want to jump over a ledge on a seemingly flat surface?
Thanks in advance!
We only see the collider of that object, and it is way bigger than the actual object. What about the collider it is colliding with? Are you sure it is exactly the shape of the other objects?
It isn't bigger; I unfortunately took the screenshot during the animation. The collider in the top right is a good bit smaller than the sprite and the collider it seems colliding with is seen as the green lines in the bottom left. There is quite a gap between those.
Here is a screenshot of what I was able to reproduce: Also there is a download for the project in which this occurs: http://www.filedropper.com/newunityproject. Just unzip it, open it, click play and then move the top quad to the right. You will see it gets stuck on a non-existant ledge.
Answer by Invertex · Jan 18, 2014 at 11:08 AM
Just thought I'd stop by and say I sorta 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: http://forum.unity3d.com/threads/223054-BoxCollider2D-colliding-with-EdgeCollider2D?p=1488478&viewfull=1#post1488478
Including a useful link about the issue. https://www.iforce2d.net/b2dtut/ghost-vertices
Answer by idhanu · Mar 31, 2016 at 12:43 PM
@Invertex try fiddling with Min Penetration For Penalty value found in Edit->Project Settings->Physics 2D. A lower value of 0.001 rather than 0.01 fixed the problem for me.
Indeed, that is the proper solution now. That option didn't exist before Unity 5.0. This post was made back around Unity 4.2 days.
I was googling around because had the same issue. This property is now obsolete and we should now be lowering Physics2D.defaultContactOffset
. Same path though, Edit -> Project Settings -> Physics 2D and then "Default Contact Offset"
Answer by Nabeel Saleem · Jun 26, 2014 at 09:18 PM
You can use third part plugin i found its effective to reduce draw call. 2d concave collider
Answer by Jinxology · Jan 08, 2014 at 12:25 AM
Use a sphere collider on the bottom of your character, rather than a box. That way he will roll up little bumps like that. You could also put a box collider on him to account for his body and head collisions.
I know about circle colliders and that's what I have done for now, yet it doesn't make up for the existing problem! But still thanks for the answer :)
Answer by FirePlantGames · May 08, 2014 at 11:08 PM
Try set the camera to orthographic instead of perspective if you haven't
That has nothing to do with the issue here. And the answer was already found and chosen ;)