- Home /
negative scale+rotation+collider
I'm making a 2d game (unity 4.3). I'm using localscale.x = -1 to flip the character to the other side. it works fine, the problem is, when I rotate the character while the x scale is negative, the collider2D doesn't react very well. it starts to shrink for some reason.
When the scale is +1 it all works fine.
But I change the scale to -1, the sprite looks great, but the collider2D reacts strange and starts to shrink and doesn't follow the sprite correctly.
Any ideas?
The problem only happens when I put the negative scale to a parent gameobject of the collider.
I rotate the character head.. but I don't see how it is related to the question..
anyway, I rotate the character head and the circle collider attached to it doesn't rotate well when the character has a negative xScale
Thanks, I asked for more info to see if I could reproduce it for myself.
I have been unable to trigger unexpected behaviour on the main gameobject, but things are playing up on sub-objects.
Rotations around the X and Y axes seem to skew both sprites and colliders in a manner consistent with the projection of a 3D object onto a 2D plane. Rotations around the Z axis spin the sprite (as expected) but also cause the size of the circle collider (but not transform scale or collider radius) to pulse in and out from full size to zero with a period of 90 degrees.
I don't have a solution that would work across the board but as a quick workaround: if your head sub-object is on the same physics layer as your main gameobject then maybe you could move the head's collider up to the main gameobject and then use a script to update it's center point to track the head position for each frame.
Answer by Psynbiotik · Jun 22, 2014 at 12:04 AM
This is the best solutions so far:
http://answers.unity3d.com/questions/581430/how-to-properly-flip-2d-character-with-new-unity43.html
Other possible solutions:
Remove rigid body on child object (this worked for me), rigid body is causing this issue.
Disable collider before changing parent, then re-enable when done.
Your answer
Follow this Question
Related Questions
Common 2D Collider flip problem 4 Answers
How to change child's rotation whithout affecting it's scale? 1 Answer
how to scale object to fit inside a room 1 Answer
How to rotate a mesh collider? 0 Answers
Animation affects the rotation.. 1 Answer