Search Unity

Question Flipping rigged Sprite on x mirrors it across the game window?

Discussion in '2D' started by Gordon_G, Jul 26, 2021.

  1. Gordon_G

    Gordon_G

    Joined:
    Jun 4, 2013
    Posts:
    372
    Hi all, We've got a rigged 2D avatar that we want to face the correct direction when we move left or right. So, in the code we multiply its transform x-scale by -1. That all works fine.

    However we have a shirt on the avatar that has an emblem that we don't want to be reversed. We have attached the emblem to a bone on the torso so that we can address it separately from the shirt.

    When we flip the avatar to the left, we should be able to mirror the emblem back to the correct orientation by either setting the Flip x property on the emblem's SpriteRenderer or by multiplying the x-scale of the emblem's transform by -1.

    Doing so does mirror the emblem back to the proper orientation, but it does not perform the transformation about the emblem sprite's pivot point, which is in the center of the sprite. It seems to mirror the sprite about the center of the game window. Either method mirrors the emblem sprite across the screen so that it looks like it is no longer on the avatar's shirt, but floating in mid air! (it may not be the actual center of the game window, but it is way off the shirt on the other side of the window)

    What is going on, and how can we prevent this from happening?
     
  2. Cornysam

    Cornysam

    Joined:
    Feb 8, 2018
    Posts:
    1,464
    Probably a dumb question but, is everything at 0, 0, 0? If you manually have to change something and that may be causing the problem, you could make a parent object and put the emblem as a child of the new parent. Then, move the child where you need it but flip the parent object (or maybe vice versa?)
     
    Gordon_G likes this.
  3. Gordon_G

    Gordon_G

    Joined:
    Jun 4, 2013
    Posts:
    372
    I thanks! I didn't think to check the location of the emblem sprite's transform. It looks like that is the problem.

    However, when I managed to fix that it still mirrors across some pivot far away from the avatar it is rigged to. And I figured it out - you have to rotate the bone it is attached to by 180 on x to get the emblem to mirror about its location. Evidently the bone controls everything, and who knows what Flip x on the SpriteRenderer does.

    Thanks to you I dug deeper to resolve the issue!
     
    Cornysam likes this.