The black curve is a mesh with a 2d EdgeCollider. The pink sphere, is a circular mesh with a circle collider at its perimeter, at Z=0. The circle object has a CHILD object, containing just a smaller circle collider, which is a trigger, offset at Z=10. I know 2d physics ignores Z… not the issue.
The issue is, in one strange circumstance, somehow, this object got itself embedded into the surface of the edge collider, and while there is contact between the inner trigger circle and the edge collider, it seems to think everything is ok, and doesn’t attempt to recalculate the position. If I move the sphere slightly up so the trigger and surface don’t touch, unity will recompute the position correctly and realize that the outer collider needs to be repositioned. I don’t even really know how this situation happened, the circle just bounced around fairly slowly and ended up like this.
I figure as a workaround I can detect collision between the inner trigger circle and the surface mesh, and when detected, disable the inner trigger for 1 frame, which also forces Unity to recalc the physics, but I’d prefer it to work properly if I can. Maybe this is just a weird edge case or anomaly that doesn’t really have proper support - where the inner collider is being used for the physics and is registering contact so it thinks things are ok? But it seems this should not be happening… the sphere shouldn’t ever embed into the surface like this, and it’s never moving fast enough to penetrate this deep in a single frame. I wondered if it’s the size of the sphere vs the size of the edge? But this is just odd. I’m concerned because I’m relying on the physics never breaking in order for people to solve puzzles, and this would totally end the entire game if it did this again.
I can see also that because this collider embedded in the surface, near to a split in the collider… i.e. this edge collider ends, and an edge collider on another object begins, Unity thinks of it as though this penetrated object is now hitting the end of that other edge collider, and so due to however the calculations work it, it may then fall through the surface completely. e.g.
On the left you can see the triangles of a separate mesh, and the green line on top being its separate edge collider, which is exactly touching the edge of the sphere… .it’s at this exact point that unity will likely make the sphere just totally fall through the whole surface.
Not sure why/how the sphere even could end up this way in the first place, but hey. Gotta fix it if it’s ever going to happen.
[edit] also I found that if I try to change the circle collider (outer) into a polygon collider, and position the sphere to be inside the surface, there is suddenly a HUGE amount of cpu activity which practically crashes unity. Not really a solution, lol.
Hey, I’m not sure if this is your issue, but this could just be a problem with tunnelling which can be reduced by setting the “Collision Detection” to “Continuous” on the Rigidbody 2D objects.
The sphere IS actually set to continuous collision detection with interpolation. And the physics is running at 120 cycles/second. I actually have never seen this before in all the time working on this project, until today it just suddenly happened out of the blue. And I’m not so sure its a tunneling thing because this sphere is not really moving fast, it was just bouncing around locally. The collider isn’t skipping all the way to the other side of the surface.
Yah it works occasionally for some reason but almost always doesn’t. Also I have a collider inside a collider, hoping the second collider will catch a collision and stop the problem, but sometimes the sphere will dangle a little bit, colliding against that inner collider for a moment, and then completely fall through the surface.
It’s a bit hard to submit a bug report… I guess we’d need an edge collider in a scene with the circle collider positioned embedded into it, and show that it does not correct its position?
Maybe a basic edge collider, with some slope change here and there, a couple of circlecolliders, a mild force to apply on fixedupdate to let them move and rotate along the edge collider. More chances to force the bug showing up.
If some Unity dev asks for it, I could provide my car prefab to let them test.
It wouldn’t be a problem for me.
One possible fix for this as I’ve found, is not using a circle collider, but instead use a POLYGON collider (2d) in the shape of a circle… it will take more polygons, but something about it seems more stable. I even put a couple of sphere under ‘pressure’ being squashed together by a moving object, and they seemed to refuse to be pushed through surfaces, much better than spheres. For now this is the fix I’m going with even though it makes for heavier physics processing.
I could be wrong but as I understand it, Unity’s 2d physics is just Box2d and therefore I doubt any bugs (if present) are going to be addressed by Unity. I’m also not convinced this is a bug (I could be wrong, so please don’t take offence). A few years ago I used Box2d extensively for a physics based game I made (with a different game engine) and experienced similar issues. All the issues I had were eventually solved by using the correct features of Box2d.
You may want to checkout the Box2D documentation ( Box2D: Overview ) as that has some info that may assist. I’d certainly look at Chain and Edge shapes. I’m not sure if/how Unity exposes these types, but it may assist with the problems you’re seeing.
I’m not sure if you’ve also tried, but the Physics2DSettings provides a lot of settings that can be tweaked to influence some aspects of the issues you’re seeing (Velocity Iterations, Position Iterations, Velocity Threshold, etc, lots there that can help).
Sorry if you’ve already tried all these things, just speaking up in case there’s something there you haven’t see/tried.
Don’t worry @larku . No offense at all.
I’m starting to work on a small scene in order to replicate the suspected bug.
I believe it’s a bug, because the same project runs as expected under Unity 4.6.
I’m aware of PhysX major version upgrade, but (I’m asking you) also Box2D has been updated in the same extent?
This could explain the behaviour disparity between the two different Unity versions.
I didn’t read the whole release notes doc, because I stopped reading at “profiler” and “render to texture”. That was enough to motivate my migration to Unity 5.
But anyway, I’m in trouble.
EDIT:
Please watch the video I shot to document the anomaly.
As you can see, the problem occurs on a random basis, with no chances to force it in a deterministic way.
And this is the packed project directory. Feel free to download and try it out into your Unity 5 environment.
Maybe I did something wrong and just don’t know what.
Any comment or suggestion will be strongly appreciated.
This is the identical problem that i have also in my project.
I have been working on physics based 2d sidescroller vehicle game and as soon as i upgraded my unity from 4.6 to 5, it broke down the edge collisions to circle colliders similiar way that the video shows.
Same here. From 4.6 to 5. Until migration to newer version, everything went fine.
Anyway, monday I did a bug report attaching the above project directory.
Waiting for a devs’ feedback.
I got some problems with this as well. Seems like at high forces, my circlecolliders just pass through the edgecollider. is this resolved? any help would be welcome