Search Unity

How to make particles render in front AND behind a sprite (Like working with a quad)

Discussion in '2D' started by SVC-Games, Mar 7, 2016.

  1. SVC-Games

    SVC-Games

    Joined:
    May 21, 2013
    Posts:
    137
    So I'm making a 2.5D game, characters using sprites, backgrounds are in 3D. Everything is going smooth until I use particles.

    Usually when having a Quad or a Plane facing the camera and a particle system, the particles generated will be either in front or behind the quad and render accordingly:
    particles1.png

    But for some reason when using a Sprite the particles show either always in front or always behind the sprite, depending of the "order in layer" value of the particle renderer.

    Here's with a lower value of "order in layer" than the sprite:
    particles2.png

    Here's with a higher value of "order in layer" than the sprite
    particles3.png

    Is there any way to make the particles show like when using a quad? I don't want to use quads for my sprites since well, they are sprites and I'll lose functionality using quads/planes.
     
  2. Hyblademin

    Hyblademin

    Joined:
    Oct 14, 2013
    Posts:
    725
    You can use two particle objects, each with about half of the total particles and with different layer orders.

    If you are using the default sorting layer, drawing order should be controllable with the transforms' z-values. I.e. if you make sure the particles also have z motion, they should give the effect you're looking for. Not sure if this stops being dependent on z-position if you are using sorting layers, because I haven't tested them myself.
     
  3. SVC-Games

    SVC-Games

    Joined:
    May 21, 2013
    Posts:
    137
    I've tried that method but the problem is that all particles have the same order in layer. That means that as soon as one of them "changes" from behind to front all the others do giving a wrong result.
     
  4. LiterallyJeff

    LiterallyJeff

    Joined:
    Jan 21, 2015
    Posts:
    2,807
    They either have to be on the same sorting order, with different Z values, or they have to have different sorting orders.

    You can make a particle system which has Z velocity so they're not just on the XY plane, and if the particle system is on the same sorting order as the sprite, you should see them going behind and in front of the sprite due to the variable Z positioning.