• 中文
  • unity中spine物体与其他物体的遮挡关系

在unity中,我试图用Spine组件来控制游戏角色,并启用unity的Transparancy Sort Axis来根据y轴动态调整角色和地图物品之间的遮挡关系。但是我发现,对于角色,unity使用中心点坐标来比较它和其他物体的y轴坐标,所以有时候遮挡关系有些不对劲。
如果使用sprite renderer,我可以调整图片的pivot位置,这样可以调整y轴的比较坐标。但是对于spine组件来说,我该怎样调整,以达到同样的效果呢?谢谢!

=====

In unity, I tried to use the Spine component to control the game characters, and enabled unity's Transparancy Sort Axis to dynamically adjust the occlusion relationship between characters and Tilemap items based on the Y-axis. But I found that for characters, unity uses the center point coordinates to compare it to the Y-axis coordinates of other objects, so sometimes the occlusion relationship is a little off.

If I use the sprite renderer, I can adjust the pivot position of the image so that I can adjust the Y-axis comparison coordinates. But for the spine component, how can I tweak it to achieve the same effect? Thank you!

Related Discussions
...

您可以偏移 skeleton.Y 值:

skeletonAnimation.Skeleton.Y = offsetY;

或者,您可以修改根骨骼的位置。 但是,除非有人反对设置 skeleton.Y,否则我们不推荐这样做。


You can offset the skeleton.Y value:

skeletonAnimation.Skeleton.Y = offsetY;

Alternatively you could modify the position of the root bone. However, we would not recommend this unless something speaks against setting skeleton.Y.

Harald wrote

您可以偏移 skeleton.Y 值:

skeletonAnimation.Skeleton.Y = offsetY;

或者,您可以修改根骨骼的位置。 但是,除非有人反对设置 skeleton.Y,否则我们不推荐这样做。


You can offset the skeleton.Y value:

skeletonAnimation.Skeleton.Y = offsetY;

Alternatively you could modify the position of the root bone. However, we would not recommend this unless something speaks against setting skeleton.Y.

感谢您的回答!我尝试了偏移Skeleton.Y,骨骼的位置确实整体偏移了,但似乎在遮挡关系上,unity还是在使用它的中心值进行比较。您提到了根骨骼,根骨骼的位置能发挥什么作用吗?它现在位于角色的脚下。

=====

Thank you for your reply! I've tried offset the Skleton.Y, and the Skeleton position is actually offset overall, but it seems unity is still using its central point for comparison when it comes to occlusion relationships.
You mentioned the root bone, what role does the position of the root bone play? It is now at the feet of the character.


我可能找到解决方式了!我的做法可能有几个毛病导致没达到想要的效果:
1.从图上看,我的角色的pivot本来就在中心,可能是因为在spine中,我把角色中心放在了原点位置。(原点应该在脚下。)
2.我没有在Sprite Renderer中将Sort Point调整为Pivot。
3.添加Sorting Group应该能解决问题。
参阅以下帖子:
http://en.esotericsoftware.com/forum/Animation-pivot-point-7713
http://en.esotericsoftware.com/forum/Pivot-point-redefined-in-the-wrong-place-13016
http://en.esotericsoftware.com/forum/Sprite-Sort-Point-for-Spine-10783
这是我的探索记录,但我还没有验证是否有效。如果起作用了,我再来记录一下。 🙂

=====

I may have found a solution! There may be several flaws in my approach which may not achieve the desired effect:

  1. It can be seen that the pivot of my character is at the center, which may be because I place the character center at the origin in the spine. (The origin should be at the foot.)
  2. I didn't adjust Sort Point to Pivot in the Sprite Renderer.
  3. Adding a Sorting Group should solve the problem.
    See the following post:
    http://en.esotericsoftware.com/forum/Animation-pivot-point-7713
    http://en.esotericsoftware.com/forum/Pivot-point-redefined-in-the-wrong-place-13016
    http://en.esotericsoftware.com/forum/Sprite-Sort-Point-for-Spine-10783
    This is my learn record, but I haven't verified it yet. If it works, I'll write it down again. 🙂

由于 SkeletonAnimation 使用 MeshRenderer 而不是 SpriteRenderer,恐怕没有选项可以将排序点设置为枢轴。 但是,您可以创建一个简单的脚本,将 meshRenderer.sortingOrder 设置为您的 Transform Y 值。


Since SkeletonAnimation uses a MeshRenderer and not a SpriteRenderer, I'm afraid there is no option to set the sort-point to the pivot. You could however create a simple script that just sets meshRenderer.sortingOrder to your Transform Y value.

Harald wrote

由于 SkeletonAnimation 使用 MeshRenderer 而不是 SpriteRenderer,恐怕没有选项可以将排序点设置为枢轴。 但是,您可以创建一个简单的脚本,将 meshRenderer.sortingOrder 设置为您的 Transform Y 值。


Since SkeletonAnimation uses a MeshRenderer and not a SpriteRenderer, I'm afraid there is no option to set the sort-point to the pivot. You could however create a simple script that just sets meshRenderer.sortingOrder to your Transform Y value.

谢谢!我尝试加了Sorting Group组件,它起作用了,虽然不知道原理是啥。这暂时够满足我的需求了!

=====

Thanks! I tried the Sorting Group component and it worked, although I don't know how. That's enough for my needs for now!

感谢您回复我们,很高兴对您有所帮助!
Thanks for getting back to us, glad it helped!