Flipping Sprites + Colliders

I’ve been searching and experimenting to find a solution to this for a week now, hopefully there’s an answer.

When I flip my object using localScale.x = -1 the sprite looks fine but the colliders go crazy (multiple GameObjects/colliders for 1 enemy).

The colliders also shrink/expand based on rotation (larger as rotation approaches 0, smaller as it approaches 360).

My hierarchy is:

Enemy [parent] ← being the one I flip via localScale.x=-1
-body
-jaw
-left_arm
-right_arm
-left_leg
-right_leg
-head

I understand it’s an issue with non-uniform scaling so I tried changing that to the following and flipping the CHILDREN instead of the parent:
Enemy [parent]
-jaw
-left_arm
-right_arm
-left_leg
-right_leg
-head

That still didn’t work.

I also tried:

Enemy [parent]
-jaw
–jaw collider
-left_arm
–left_arm collider
-right_arm
–right_arm collider
-left_leg
–left_leg collider
-right_leg
–right_leg collider
-head
–head collider

I tried this solution as well but just couldn’t figure it out.

Any help would be GREATLY appreciated! I’ve been stuck on this for a week.

1449068--78233--$6DoF5xM.png

1 Like

That’s odd. Could you submit a bug report?

Also, rotationg around Y by 180 should work with Sprites as well.

Upgrade to the latest version of Unity (4.3.1), this seemed to have fixed this issue.

DigiScot: I’m on 4.3.1f1

TomasJ: Rotating on the Y causes weird issues. The dinosaur is made up of several sprites arranged on the Z layer. Rotating Y to 180 makes his left leg in front of the right, etc. You can fix the look by inverting the Z position BUT the colliders don’t move with the sprites:

I read something the other day by someone on your team, I believe Eric, saying that you should only rotate sprites on the Z axis in a 2D environment. Obviously you can’t “flip” a sprite by rotating it on the Z.

Hi Brutang, turns out I was wrong (as you know) with the version, it wasn’t that it started working for me, it’s because I changed to using the polygon collider, which does rotate correctly. It’s not ideal, but it’s workable till they fix it, and you can easily delete points to get it down to a similar number or verts, tho I couldn’t say how it compares in performance!

The colliders are all Polygon Collider 2Ds; 6 of them. Rotating on the Y or flipping the parent via localScale.x=-1 both cause issues. Flipping via localScale causes non-uniform scaling issues (like shrinking/expanding depending on rotation) and rotating on the Y doesn’t adjust the colliders (as shown in the image).

I’d love to see how you do it via code or an image as I’m at a loss for how to fix this!

I had collider issues when flipping things but I found I had to… kind of rotate things in a weird way.

Pause the game and in the editor play with the rotational values to see if you find what works.

I had to do a Quaternion.Euler(0, 90, 270) if the object was on the left and a Quaternion.Euler(0, 270, 90) if it was on the right to get the correct effects, depending on which direction something was instantiated then rotated via Quaternion.LookAt(x)

Hopefully something like this helps.

It’s the Rigidbody that messes it up, if you don’t have one, poly colliders rotates fine that’s why it was ok in my tests I did. Really annoying this one!

We reproduced this case and a fix will be available in the next release. Sorry for any inconvenience.

Great news TomasJ!

Thanks, TomasJ!

Looking forward to it.

doing a localscale = -1 really messes with the colliders. It would take a working collider and instantly mess up the detection once the scale was reversed, I had to resort to rotation on y

I solved this by enabling and re-enabling the collider every time it’s rotation changes using the second method you described. An ugly fix, but it does the job.

Any idea when the next release will be? I really need this fix :frowning:
Thank you

Has this been fixed with 4.3.3 ?
I still seem to have really weird things going on when rotating child objects of flipped sprites.

I confirm that this problem has NOT been fixed in Unity 4.3.3 :evil:

:frowning: really sad news

i had all these issues on my previous project and i had to abandon it , not only colliders, joints go nuts as well, subscribed to this thread i hope unity fix it soon

Yes I confirm that joints go nuts as well.

@TomasJ
Can you please give us an ETA on when all of this will get fixed?
Thanks

BUMP! :stuck_out_tongue:

@MelvMay can you please tell us if this will be fixed in the next release?

Thanks