• Unity
  • Spine [ bounding box] in unity

  • Editado
Related Discussions
...

How can I set it so that the bounding box can follow the character's body deformation in unity?🙂

The bounding box is deformed with the character's body in spine, but it will only remain in the default standby state in unity.

I'm afraid to say that the spine-unity runtime does not support updating collider shapes yet. It would anyway be a very bad idea to update the mesh of a PolygonCollider2D at runtime with the animation. Unity has just introduced a new collider type CustomCollider2D in Unity 2021.2+ which would allow updates of colliders at runtime with reasonable performance.

User @Jamez0r on the forum once started an implementation, as can be seen on this forum thread:
[Discussion] Mutable physics colliders in Unity 2021.2
Unfortuantely the thread ends without any results or insights being published yet.

In your case we would however strongly recommend to not use a single polygon collider at all, since that's a very computation-heavy solution for the physics engine. Instead it would be much better performance wise to use multiple box colliders. You then typically use BoneFollower components to let them follow the respective bones and adjust the bounding box shape in Unity. Also be aware that gameplay-wise, you will rarely want the collision shapes to exactly match the character for the best user experience. In e.g. beat-em-up games the hit-boxes are typically larger than the character to provide the best game-feel, as can be seen in this forum posting by Nate:
Spine - libGDX collision detection

Harald escribió

I'm afraid to say that the spine-unity runtime does not support updating collider shapes yet. It would anyway be a very bad idea to update the mesh of a PolygonCollider2D at runtime with the animation. Unity has just introduced a new collider type CustomCollider2D in Unity 2021.2+ which would allow updates of colliders at runtime with reasonable performance.

User @Jamez0r on the forum once started an implementation, as can be seen on this forum thread:
[Discussion] Mutable physics colliders in Unity 2021.2
Unfortuantely the thread ends without any results or insights being published yet.

In your case we would however strongly recommend to not use a single polygon collider at all, since that's a very computation-heavy solution for the physics engine. Instead it would be much better performance wise to use multiple box colliders. You then typically use BoneFollower components to let them follow the respective bones and adjust the bounding box shape in Unity. Also be aware that gameplay-wise, you will rarely want the collision shapes to exactly match the character for the best user experience. In e.g. beat-em-up games the hit-boxes are typically larger than the character to provide the best game-feel, as can be seen in this forum posting by Nate:
Spine - libGDX collision detection

Thank you for your reply. It's very helpful to me :grinfake :grinfake

5 días más tarde

I updated my post ( [Discussion] Mutable physics colliders in Unity 2021.2) with some additional info and code - unfortunately I'm super busy with my project so haven't been able to finish working out the kinks and testing.

Thanks so much for your work and for sharing your code and for your writeup @Jamez0r! Much appreciated, I'm sure it will help!