Search Unity

Resolved Weird 2D Sprite behaviour with tilemaps

Discussion in '2D' started by anglojojo, Nov 28, 2020.

  1. anglojojo

    anglojojo

    Joined:
    Nov 11, 2020
    Posts:
    18
    Hello all,

    I'm pretty new to Unity and everything related to game dev. Just started a month ago.

    I started learning to use Tile Maps and to be honest its making life difficullt.

    I came across a weird issue, where if I change directions on the X axis while on the tiles, the sprite will shrink significantly, as shown in the images, I can't figure out why this is heppening? any clues? please help.

    When facing right, the sprite size is normal:


    When turning left, the sprite's size shrinks:


    Note: my player is using animations.

    I've only noticed this issue when using Tile Maps... besides that the tile map isn't redering nicely, any clues?

    My configuration:
    My Tile map was exported via Aseprite.
    On Unity I sliced it 32x32 cell size.

    In the inspector of the tilemap I set the following:
    Pixel Per Unit = 32 pixels.
    Filter: No filter
    Compression: No comression
    The rest of the settings I left on default.

    The grid size, and palette sizing I left all default/automatic.
    I added a 2D material to the Tilemap renderer. (material shader: sprites/default with Pixel Snap selected)
     

    Attached Files:

    • good.jpg
      good.jpg
      File size:
      24.7 KB
      Views:
      309
    • bad.jpg
      bad.jpg
      File size:
      22.7 KB
      Views:
      307
  2. anglojojo

    anglojojo

    Joined:
    Nov 11, 2020
    Posts:
    18
    Update:
    I did some testing and found the following...
    When I comment out the following line of code of flipping the object, the issue is gone.
    Code (CSharp):
    1. transform.Rotate(transform.position.x, 180, transform.position.z);
    But then, in what method should I flip the object when changing directions? I am aware of the sprite renderer flip function, but thats specific to the sprite and not all of the components. Any solution for a newb please?

    Note: I added pixel perfect component to my camera which resolved some issues with pixel rendering during motion.

    Thanks in advance.
     
  3. anglojojo

    anglojojo

    Joined:
    Nov 11, 2020
    Posts:
    18
    Final update:

    Ok I figured out a way to make it work, but I don't really understand the technicalities.

    I used this line of code instead of the transform.Rotate...
    Code (CSharp):
    1. transform.localScale = new Vector3(transform.localScale.x * -1, transform.localScale.y, transform.localScale.z);
    Now when I change directions specific to the left while on tiled sprites, my main player object's sprite won't shrink anymore.

    If anyone could please explain the reason for this from the technical stand point, I would be greatful.

    Thanks.
     
  4. raarc

    raarc

    Joined:
    Jun 15, 2020
    Posts:
    535
    is your tilemap child of the player or vice versa? they should not be children of eachother
     
  5. anglojojo

    anglojojo

    Joined:
    Nov 11, 2020
    Posts:
    18
    Nope, my TileMap is only the child of the Grid Object (defaults).