- Home /
Mirroring sprite around arbitrary axis causes collision issues
I'm using the bean (body) sprite from the 2D platformer demo that Unity released. I stripped down the script a bit, put a polygon collider on the bean, and made the Flip() function mirror the bean around an arbitrary axis:
void Flip()
{
// Switch the way the player is labelled as facing.
facingRight = !facingRight;
var oldSqrMag = new Vector2(transform.localScale.x, transform.localScale.y).magnitude;
var oldPos = transform.position;
transform.parent = flipperTransform;
var theVec = flipperTransform.localScale;
theVec.x *= -1;
flipperTransform.localScale = theVec;
transform.parent = null;
transform.localScale *= oldSqrMag / (new Vector2(transform.localScale.x, transform.localScale.y).magnitude);
var scl = transform.localScale;
scl.z = 1;
transform.localScale = scl;
transform.position = oldPos;
}
Now with only a rigidbody2d and polygon collider on the bean, it can "fall" so that it's lying on its side with both "points" colliding with the ground. If you call Flip() (which just mirrors it about the y-axis) while it's in this state, the bean will sometimes fall through whatever surface it's sitting on. Anyone have ideas? It seems to happen when there are multiple contact points between the sprite and the ground.
Your answer
![](https://koobas.hobune.stream/wayback/20220613125830im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Fitting 2D collider to a sprite 0 Answers
[2D] How do you rotate a 2D sprite left and right with C#? 2 Answers
Collision detection not working properly with 2D sprites 1 Answer
problem with a box collider 2d. 0 Answers
Wanting to have a sprite animation to only start playing once the player collides with it? 1 Answer