Hello Guest

Author Topic: Sprite Sorting  (Read 4883 times)

Copywright

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 33
    • View Profile
Sprite Sorting
« on: March 30, 2013, 04:01:58 pm »
Hey,

I've been trying to implement a method for sorting sprite based on the position of their feet. I was going to do something with layers, when the position of the sprite's feet will determine what layer/depth it's on, but playing with the layering could make collision detection problematic.

I was wondering if you guys had any solution for working out sprite sorting, in a beat-em-up sort of way. All beat-em-ups I see made in Unity with 2D graphics are all fully 3D (Legend of Dungeon, another by an admin at TIGSource), and I want to know if there's a way around going completely 3D.

Any help is greatly appreciated! Thanks in advance.

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: Sprite Sorting
« Reply #1 on: March 30, 2013, 05:31:28 pm »
Quote
but playing with the layering could make collision detection problematic.
Could you elaborate? I can't think of any downside to doing this, but perhaps there is something I have missed?

Copywright

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 33
    • View Profile
Re: Sprite Sorting
« Reply #2 on: March 30, 2013, 08:11:32 pm »
Well, think is, I'm not exactly sure how I'd be able to handle all the layers. I was thinking of doing something where when the player moves, the layer of the sprite will change based the position and layer of the other sprite's feet (or other base). However, would the layers pile up with bigger scenes? Unity layers are limited in #, right?

I just want to know all my options for implementation.


unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: Sprite Sorting
« Reply #3 on: March 30, 2013, 08:48:55 pm »
Oh. To sort all you need is the zvalue.
Give each character one z value, and move them back or forward in z depending on what you want to be visible in front of the other.

Copywright

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 33
    • View Profile
Re: Sprite Sorting
« Reply #4 on: March 30, 2013, 11:59:38 pm »
How will this work in collision detection? The sprite will have to be on the same z value to hit each other, so whart would be the best way to do this?

Would it be something where if Sprite1.y  < Sprite2.y, Sprite1.z -= Sprite2.z, and the colliders are at 1 z-value? Or am I just thinking about this the wrong way? Any suggestion how use Z sorting, while keeping movement and collision working?

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: Sprite Sorting
« Reply #5 on: March 31, 2013, 02:03:32 am »
It should be fine, as long as your colliders are "deep" enough that they collide, even with the z offsets. If youre using the built in collider setup system, just set it in "collider depth" in the sprite collection editor.