I m struggling with odd behaviour for RigidBody2D.
I created game object (consisting only of Transform) “Parent”.
I added multiple children into “Parent”. Into children I added polygon colliders and also rigidBody2D set to Dynamic.
My problem is that it seems like RigidBody2D doubled PolygonColliders on Children.
Thank you for reply…
Actually this is the case. My child gameObject is prefab and it has PolygonCollider2D, RigidBody2D, Mesh filter and MeshRenderer. Before I instantiate it, I modify mesh and then assign points to PolygonCollider2D.
You can see on image that for one selected child :
There is only one path for polygonCollider2D, and only one polygonCollider2D component on the object
I can modify original path of polygonCollider, but for physics it is ignored.
It is also displaying another polygonCollider2D, and I don’t know where it come from - seems like any offsetted version? Physic is based on this collider, not on original.
This is very odd. I found where is problem. This unwanted behaviour occurs only when I set “Parent”'s scale x and y to be not equal. So when I set parent’s transform scale x = 5, and transform scale y = 5, then everything is fine. But when I set it to x = 2 and y = 5, then this problem occurs. Thank you for you help
Hello MelvMay,
I just tested it again, on completely new project and I am getting the same behaviour. I uploaded it to you personal folder.
I am using unity 2019.2.10f1.
So in order to reproduce bug:
Set parent scale x and y to be different values: let say x = 3, y = 1.
Now when you look on child (it is frog in sample project) collider**, everything is fine**. It is same. But if you lift child, and let it drop on ground, and then when you look on collider it looks doubled.
I am attaching picture, you can see here how collider is doubled.
So first thing to note is that this is “just” a gizmo thing, there are not two colliders. The gizmo first draws the physics shapes (the sub-polygons) and you can see that count in the PolygonCollider2D Info roll-out in the inspector. It then draws the outline that you actually specified by editing. This outline is used to create those sub-shapes.
Anyway, a couple of things are at play here that isn’t too obvious. The first is that the outline gizmo is using the raw scaling when it shouldn’t so this is the “double” collider you’re seeing and this outline is incorrect so on that basis alone I would submit this as a bug report and send me the case number and I can get it fixed. It’s the non-uniform scaling that’s throwing it off.
The second is nothing to do with physics and it’s the first time I’ve noticed this but for the SpriteRenderer there seems to be a difference when you use non-uniform scaling on a parent as opposed the same scaling on the GO the SR is on. I’ve just asked the 2D team which this is the case. It does look like scaling is applied post-rotation in that case. This means that it won’t be the same as the collider shapes (2D or 3D for instance). Collider shapes are static and are not dynamically scaled in the XY axis. They are scaled correctly when they’re created and from then on they just move or rotate as the body does.
So in short; it’s not a double collider but an outline gizmo rendering issue specifically for the PolygonCollider2D.