Hi everyone. I realise this is partly a Unity-specific problem, but after a lot of searching I haven’t found a solution, so I’m asking here.

I’m making a 2.5-D game. The player, enemies and some other elements are Spine skeletons, while many props and decorations are simple quads with sprite textures so they can sit in 3-D space and cast/receive shadows.

Here’s the issue: the main character’s skeleton is positioned so that Spine’s origin (0, 0) is at the feet, resting exactly on the Unity ground plane. When the character attacks toward the camera (facing “down” on screen), the sword-wielding arm dips below Spine’s 0, 0 because of the perspective tilt. In Unity this means the lower part of the sprite clips into the ground mesh and appears “cut off”.

What I need is a way to have the Spine character render just a little after the ground plane so the weapon and arm aren’t clipped, but still allow the character to go behind ground pieces that are actually higher than the feet (e.g. slopes, steps, raised platforms).

Thank you for your help, I hope you can help me finding a solution to this problem which is driving me crazy haha.

Related Discussions
...

To address the issue of your Spine character's arm and weapon clipping into the ground mesh in a 2.5D game, you can consider a few approaches. One solution is to adjust the rendering order by manipulating the Z-position of the character or specific parts of the character, such as the arm or weapon, to ensure they render after the ground plane. This can be done programmatically by slightly adjusting the Z-position of the problematic parts during the animation where clipping occurs. Another approach is to use Unity's sorting layers or order in layer settings to control the rendering order, ensuring that the character's arm and weapon are rendered after the ground plane. Additionally, you can explore using shaders that handle depth sorting more effectively, allowing for better control over what renders in front or behind other objects.

@Yimec Theoretically you could also adjust (a copy of) the used shaders and add a z-bias to offset the mesh slightly. Likely this introduces undesired intersections with other parts however.

I'm not quite sure I understand your exact setup (camera, skeleton and Unity sprite angles) and what is actually intersecting, could you please show a screenshot which shows you issue, best including both Scene view and Game View?

Hi @Harald ,

I’ve tried what you suggested—modifying the shader by adding a couple of units’ offset to the Z—but I haven’t noticed any difference.

I’m sending you a screenshot of the Spine object (with a “broken” material, since the NDA keeps me from showing the character), and you can clearly see that the large rectangle on the right (a Spine VFX) gets clipped horizontally right where it meets the ground—and that’s exactly the part I need to render on top.

The camera sits at a 30-degree angle relative to the ground, and the 2-D objects (quads) always face the camera. It’s using an orthographic projection.

Sorry I can’t share more images—NDAs make that tricky, haha.

I hope the screenshot helps illustrate what I’m trying to solve.

Thanks a ton!!

  • Harald님이 이에 답장했습니다.

    Yimec I’ve tried what you suggested—modifying the shader by adding a couple of units’ offset to the Z—but I haven’t noticed any difference.

    Thanks for the screenshot, that helps a lot. No need for textures here BTW, it's clear enough.

    This clearly looks like a Z-buffer issue, where an offset should resolve it or at least change it. How did you add the couple of units to the shader? Have you also tried offsetting the GameObject in the Scene view, as this should also have a noticable effect as well?

    Hi Again @Harald

    I'm glad it’s understood.
    Adjusting the offset on the relevant axis and in the scene helps up to a point, but it introduces other issues—for example, the distance between the sprite and its shadow.

    As for the shader, in the forward-lit pass I added an offset of -1, -1 (I don’t understand the units and can’t give more details because I did it with ChatGPT and this is all I managed to salvage).

    Pass
    {
        Name "ForwardLit"
        Tags { "LightMode"="UniversalForward" }
    
        Blend [_SrcBlend] [_DstBlend]
        Cull [_Cull]
    
        ZWrite On          // forces depth write
        Offset -1, -1      // pushes towards the camera

    Including these tags:

    Tags
    {
        "RenderPipeline"="UniversalPipeline"
        "Queue"="AlphaTest"                 //  = 2450
        "RenderType"="TransparentCutout"
        "IgnoreProjector"="True"
        "CanUseSpriteAtlas"="True"
    }

    And using the shader included in the URP Spine addon with this setup:

    Thank you again Harald

    @Yimec You likely need to set much larger values like Offset -100, 0, chatGPT likely suggested -1 as this counters z-fighting, but you don't have your objects on the same depth plane fighting.

    In general however, it's likely a better idea to think about your scene setup, what do you want in the first place. You are creating two quads at a 30 degree angle to one another and don't like that they are intersecting. Now you can solve this in various ways, but you need to understand what you're doing. Think about the desired sorting and desired depth writing and interaction. If you don't know what you are doing and are just adding shader statements that chatGPT suggests to you, you will sooner or later run into problems as your scene starts to fall apart.

    BTW: I just remembered this related forum thread on an isometric game as well, perhaps it's of some help to you:
    https://esotericsoftware.com/forum/d/25182-render-spine-in-3d-world