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

Resolved How to make particles respect a custom sorting axis Y ?

Discussion in '2D' started by SunnyValleyStudio, Oct 27, 2022.

  1. SunnyValleyStudio

    SunnyValleyStudio

    Joined:
    Mar 24, 2017
    Posts:
    67
    Hey!

    I'm trying to improve my rain effect and my rain ripple seems to be using the pivot of the particle system (rather than each separate particle) for sorting.

    My project is using URP with a custom sorting axis set Y axis.



    The problem is as on the attached gif. When I place the whole system above my player all the particles shows behind. When I place it in front all the particles shows in front.

    Is there a setting / a way to make each particle be rendered based on its own pivot? Or maybe I am doing something wrong with my settings - I'm still exploring the particle system so it might be my fault :)



    The bigger issue that I am trying to solve is to make the rain spawn only around the player and hit only the ground and the roof of a house but not the other part of the hound / or other objects like trees that are around.

    I guess that to solve that I would require some shader magic.

    Here are my settings:
    Particle rendering settings (the render on the same layer as agent)

    upload_2022-10-27_16-1-31.png

    My custom custom sorting axis setup in URP:
    upload_2022-10-27_16-1-3.png


    Thanks!
    -Peter
     
  2. dynamicbutter

    dynamicbutter

    Joined:
    Jun 11, 2021
    Posts:
    61
    Hi Peter. Have you tried adjusting the sorting layer if or the order in layer? Making those higher than your character sprite layer should cause the rain to appear on top.
     
    SunnyValleyStudio likes this.
  3. SunnyValleyStudio

    SunnyValleyStudio

    Joined:
    Mar 24, 2017
    Posts:
    67
    Yeah! Currently (as a fix) I am spawning the rain under the "Agent" layer (on the layer below it) which is used for the custom sorting axis.

    The custom sorting axis allows the player to go behind the house / trees so if I put the rain on the layer below the rain drops will not hit the roof of the house (but they will never spawn on the trees themselves - which is a good thing).

    I guess this solution + some trickery to add rain drop particles on the roof itself will be better than trying to fix it globally.

    Thanks for the help!
     
    Last edited: Oct 28, 2022
  4. Lo-renzo

    Lo-renzo

    Joined:
    Apr 8, 2018
    Posts:
    1,319
    The way I'd solve this problem is with two different particle systems. The first has a Sorting Order above of the roof. The other has an Order below to the character but above the floor. For each, I'd manually emit by script the positions I want splashes to hit. For the roof splashes, only emit on roofs or other appropriate objects. Perhaps the objects need a physics collider layer or some other means to detect. For the ground splashes, I'd emit on screen and slightly off-screen.

    https://docs.unity3d.com/ScriptReference/ParticleSystem.Emit.html
     
  5. SunnyValleyStudio

    SunnyValleyStudio

    Joined:
    Mar 24, 2017
    Posts:
    67
    Thanks!
    The problem with this is that roof needs to be on the layer that the player is on for the custom axis sorting to work (show player behind the house /roof or in fron of the house).
    With a single building an additional small area particle system works. With more houses (like a town) adding a new particle system to each house seems inefficient. Either the house sprite would have to be split into a roof and an exterior or some sort of masking of the particles would work i think.