Search Unity

2D sprite flip/transform keeps adding space on the sides of the image (not turning correctly) ?

Discussion in '2D' started by blavatsky, Dec 5, 2019.

  1. blavatsky

    blavatsky

    Joined:
    Sep 23, 2019
    Posts:
    18
    I have a sprite (with a sprite skin/2D animation bones) I need to flip as it changes walking direction, but both sprite.FlipX and transform.eulerAngles = new Vector3(0, 0, 0) are adding extra space around it, almost like it has retained some old metadata before I trimmed up the PNG. Is there another trick other than setting the pivot point in the sprite editor? I just need a clean turn for the character changes directions without padding.
     
  2. MisterSkitz

    MisterSkitz

    Joined:
    Sep 2, 2015
    Posts:
    833
    That isn't what's happening. Your image is offset so it appears normal in the direction you're facing originally, however, when you flip the object, you're seeing the outer edge of the image appearing as a gap. You want to scale your image to the size of the character, at least on the left/right so when you flip directions, that gap is no longer there. You have to remember, it is an image.

    Take the image back into your photo editor, size it to fit, re-import it and put it in the sprite renderer. I think this should work.
     
    blavatsky likes this.
  3. blavatsky

    blavatsky

    Joined:
    Sep 23, 2019
    Posts:
    18
    Thank you! I'll try this again. That is what is so odd, the image in the photo editor has zero gaps around it, it's cropped to the very edge of the character. Maybe the first time I imported it, I had not fixed that yet and it's somehow retained that metadata.
     
    MisterSkitz likes this.
  4. MisterSkitz

    MisterSkitz

    Joined:
    Sep 2, 2015
    Posts:
    833
    That's where re-importing comes into play rather than making another image and substituting, I think. The metadata aspect anyway. If what you say is true and this doesn't resolve your issue, then I suggest creating an offset value and try to make the image flip according to where the other side was facing. (The Vector2.position )