What are you doing to test this? take a normal rectangle sprite, rotate it on the Z axis say 45o, then rotate it on the Y 180o, does everything look as it should to you?
That breaks batching though; rotating does not. It seems like a bug, since polygon and edge colliders work with arbitrary rotation, and I thought I read that box colliders in Box2D are implemented with polygon colliders under the hood.
Rotating 2D colliders in the X/Y axes is not supported. By this I mean that all 2D colliders ignore transform X/Y rotation and only use Z. This is especially important when you consider that we’re limited in what deformation we can achieve via Box2D for some collider types such as the Circle collider. Allowing this kind of arbitrary transform would mean Box2D would need to support ellipse (even sheered ones) which it doesn’t support.
This only parts of the transform component that are used are:
X/Y position (Z ignored)
Z rotation (X/Y ignored)
X/Y scale (Z ignored)
The colliders are not part of the SpriteRenderer component so whatever it does or doesn’t use isn’t tied into any of the colliders.
Related to my other post… a GameObject with Rigidbody2D + Interpolation on cannot rotate the X/Y axis at all. How do I rotate that? It absolutely will not rotate the GameObject. I don’t want, nor am I trying, to rotate the collider/rigidbody, just the GameObject.
I made a workaround of putting the rigidbody2D/collider2D in a different object than what I am rotating (sprite, animation, etc.) but… wow, threw me for a loop for like a week.
I am also having trouble changing the Position of the Circle Collider 2D, it moves in the X position but changing the Y position seems to have no affect. Can anybody confirm this please? Just set the Scene View to 2D, add a Circle Collider 2D to your GameObject and try changing the Y position.
I don’t understand the comment of “flip the signs of the z rotation and localScale”… I mean, I’m obviously missing something but why would that do anything at all? When looking at the character before it is flipped the Z rotation is set to zero. The Scale is set to 1. Setting the z scale to -1 has no effect on the sprite displayed… and obviously 0 * -1 is still zero. So the result is an unflipped image, and it doesn’t solve the problem at all. ??? what am I missing ?
It’s not the Z scale. It’s the X scale to flip horizontally, Y scale to flip vertically. Once you flip it (either way), any rotations you apply (which should be in Z) must also be sign-flipped, although at 0 rotation that’s irrelevant (0 * -1 = 0).
As long as you flip and rotate the same transform, you won’t encounter any collider bugs, but if you flip a transform and then rotate a child Game Object, that child’s colliders will not rotate correctly (in the version current at this time, reportedly already fixed for the next version).
It seems that rotating a Collider2D on Y, works in the inspector, but when I try to do it by code, it rotates visually in the inspector but stays physically in the same place. Is this due to the fact the rotation is not supported on Y for 2D colliders?
EDIT:
Actually I managed to fix this problem by adding a ridigbody to the object containing the collider. It seems to update the collider to the correct position.
Same thing as Mish. Primitive 2D colliders seems to work well when paired with a rigidbody2d, I mean that you can rotate by X and Y and the collider also rotates, BUT ONLY IN INSPECTOR. When I change those X and Y rotation in script colliders don’t do the job, they appear bad placed. Any help will be appreciated.