When using negative scale to flip a gameobject, everything looks fine except if there are rotated child gameobjects containing box colliders. In this case the box colliders will be positioned correctly but with the wrong rotation and size.
This is very easy to reproduce.
Create a new gameobject A
Create another gameobject B and attach to A
Add a box collider to B
Rotate B by 20 in Y
Set Scale X to -1 on A
Observe that the box collider on B doesn’t flip correctly, with the wrong rotation and size
Yeah I’ve also noticed issues with scale and the physics system. My guess would be that there are many assumptions/pre calculations/optimisations made in the physics engine to help make it run faster. Some of these assumptions/pre calculations/optimisations must break when scaling un-uniformly and/or negatively.
I’m going to assume you’ll have to change the actual behavior. Rather than descaling it until it’s negative, scale it down to near 0 and then rotate it appropriately and then rescale it back to 1.
That should work until some abstract day we potentially get this behavior… although I don’t see it happening unless people make it a well-known issue
Not really sure what you mean. I’m seeing this issue too and it’s a serious bug in Unity.
The code looks like the following. Also it’s not consistent. Sometimes the box collider gets shrunk, sometimes it doesn’t. It seems arbitrary and unpredictable. Oh… and sometimes it grows back to the right size randomly as well.
I did realize a workaround, I think, but I’m still testing it… which is to write a script that disables and re-enables the box colliders after doing the flip. Because the box collider size in the inspector is still the correct size. It’s just internally somehow unity has shrunk it (in the scene view), but when you disable and re-enable it gets the correct size again because it uses the value from the inspector again to re-create the collider.
But I don’t understand your comment of “…rather than descaling it until it’s negative…” etc… this is a very simple flip, and it’s a well regarded way to do a horizontal flip. So why wouldn’t this work.
I’ve been unable to find a good solution to a very similar issue, except I’m not using any physics objects, just trying to get quads to rotate when their parent has a negative x-scale. I posted about it on answers a while ago here, and just ran into it again ugh. I would love to see -x scaling work correctly!
Same problem. Have parent object with x scale = -1. Want to set child positions and rotations, but positioning is not mirrored, and rotations get broken. My work-around is before updating child rot/pos set the parent scale to 1,1,1 then set child rot/pos, then set parent scale to -1,1,1 which then properly mirrors all children. Using Unity 5.4.