Search Unity

How to align different sized Sprites with the ground

Discussion in '2D' started by SmithUnityNoob, Mar 2, 2021.

  1. SmithUnityNoob

    SmithUnityNoob

    Joined:
    Mar 2, 2021
    Posts:
    5
    Hi,

    For context I'm trying to make a Pokémon clone and I've currently got a player object and an enemy object which I can assign a Pokémon as an asset in the battle mode.

    The problem is, the sprites I've got are all aligned in the centre and it's causing an issue due to all the Pokémon being different sizes and thus some go through the bottom of the ground / float above it. I can't think of how to get it so they are all aligned in the middle of the battle circle regardless of their sprite size? The only option I can think of is to manually go through each sprite and move their feet to the bottom of the image but that's gonna take ages if I want to include hundreds

    I'm very new to Unity and relying on tutorials but I've googled for the last hour and can't describe what the issue is concisely enough to find an answer
     
  2. Lo-renzo

    Lo-renzo

    Joined:
    Apr 8, 2018
    Posts:
    1,513
    Perhaps I misunderstand your problem, but it sounds like your ground should be in a lower Order in Layer and your characters should be in a larger Order in Layer. This is an option on the SpriteRenderer. If you make that adjustment, then the ground will always be behind the characters. If that sounds very offbase, an illustration / screenshot would help us understand the problem better.

    But you should also be aware of all the other sorting information and tools at your disposal.

    In the SpriteEditor change the pivot point of your sprite to being in the correct spot. This pivot point influences where the "behind" / "in front" point is when sorting.
    https://docs.unity3d.com/Manual/SpriteEditor.html

    On the SpriteRenderer use Sprite Sort Point : Pivot
    https://docs.unity3d.com/Manual/class-SpriteRenderer.html

    Sorting Groups can be very useful when you have a character composed of several sprites that need to all sort together. Creating a Sorting Group a parent gameobject can be used to make SpriteRenderers childed to that parent sort at the parent's position relative to other objects and characters.
    https://docs.unity3d.com/Manual/class-SortingGroup.html

    More information on 2D Sorting:
    https://docs.unity3d.com/Manual/2DSorting.html
     
  3. SmithUnityNoob

    SmithUnityNoob

    Joined:
    Mar 2, 2021
    Posts:
    5

    Hi, thanks for your reply but I don't think I explained it very well!

    Currently I've got a player and enemy object which I assign a sprite to when the battle commences.

    upload_2021-3-4_10-24-40.png

    I've put in Squirtle as an example as the enemy unit.
    He's in the middle of the grass quite nicely.

    However, if the enemy pokemon was a bigger pokemon:

    upload_2021-3-4_10-26-1.png

    You can see Charizard doesn't fit in the middle properly.

    Looking at the sprites at the bottom you can see this is because the resources I downloaded have the sprite in the middle instead of at the bottom.

    upload_2021-3-4_10-27-55.png

    Is there anyway to fix this without manually editing each image and moving the sprite down to the same position?
     
  4. Lo-renzo

    Lo-renzo

    Joined:
    Apr 8, 2018
    Posts:
    1,513
    Yeah, just adjust the pivot in the SpriteEditor.

    If you put every character's pivot at the feet, and you use a SpriteRenderer with its Sort Point set to Pivot, then it'll have its feet wherever you place the transform. That would allow you to put the gameobject's transform in the middle of the grass, and their feet would always be centered there.
     
  5. SmithUnityNoob

    SmithUnityNoob

    Joined:
    Mar 2, 2021
    Posts:
    5

    Do I have to manually go through each sprite individually and adjust the pivot point then? Each sprite is a different image so I'd have to go through 800~
     
  6. Lo-renzo

    Lo-renzo

    Joined:
    Apr 8, 2018
    Posts:
    1,513
    Correct, it's not automatic.
     
  7. SmithUnityNoob

    SmithUnityNoob

    Joined:
    Mar 2, 2021
    Posts:
    5
    Yeah, that's why I was wondering if there's a way to do this without me having to manually go through each image
     
  8. rarac

    rarac

    Joined:
    Feb 14, 2021
    Posts:
    570
    you can create an import preset that automatically sets the pivot to bottom when you import new files

    set your new preset as default when importing images and

    then reimport all your images and their pivot will be on bottom
     
  9. SmithUnityNoob

    SmithUnityNoob

    Joined:
    Mar 2, 2021
    Posts:
    5
    I will give that a try! Thank you
     
  10. zaynehemingway

    zaynehemingway

    Joined:
    Nov 1, 2021
    Posts:
    1
    Can you screenshot what worked please? I'm struggling with the same issue.