Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

2D character walking around objects?

Discussion in '2D' started by AnAlienDream, Dec 10, 2019.

  1. AnAlienDream

    AnAlienDream

    Joined:
    Oct 19, 2019
    Posts:
    12
    I'm trying to decorate my 2D world with 2D objects, and I want the player to be able to walk "around" the objects, so that the character can stand in front of the object, collide with it and walk behind it. I've achieved the effect in some way, but when you move the character down from the top part of the object, it clips on top of it. (See the pictures: )
    The characters appears in the front of the object as she should:
    Collidea.png
    The character can also go behind the object at the upper part of Y-axis...
    collideb.png
    ...but when she walks down, she clips on the top!
    collidec.png

    I tried to look up multiple threads and a couple of videos on how to achieve this effect, and they all seemed to use a line of code. However, when I looked at the newest comments, they all said that you don't need the code, since Unity already has a built-in way to do it (Graphics settings > Transparency sort mode), so maybe the tutorials were just outdated. Still, I've been trying to mess around with the order of sorting layers, pivot points and transparency sort mode settings, but nothing seems to help.

    (Currently, I have both the house and the playable character in the same sorting layer, their pivot is set to bottom and transparency sort axis Y is 1)
     
  2. LiterallyJeff

    LiterallyJeff

    Joined:
    Jan 21, 2015
    Posts:
    2,802
    Is the SpriteRenderer for the house using "Pivot" for the "Sprite Sort Point"?

    Also, the pivot for the house should probably be where the back of the house would meet the ground, some distance up from the bottom, because the character would only be "behind" the house when it is above that Y position.

    Also make sure your transparency sort mode is set to CustomAxis in order to actually use the custom axis.
     
    MisterSkitz likes this.
  3. AnAlienDream

    AnAlienDream

    Joined:
    Oct 19, 2019
    Posts:
    12
    Got it, the problem was that the Sprite sort point wasn't set to pivot.
    One click would've fixed the problem I tried to solve for days :rolleyes:
     
    LiterallyJeff likes this.