diff --git a/spine-unity/Assets/Spine/Runtime/spine-unity/Components/SkeletonUtility/SkeletonUtility.cs b/spine-unity/Assets/Spine/Runtime/spine-unity/Components/SkeletonUtility/SkeletonUtility.cs index 859888e34..a39214317 100644 --- a/spine-unity/Assets/Spine/Runtime/spine-unity/Components/SkeletonUtility/SkeletonUtility.cs +++ b/spine-unity/Assets/Spine/Runtime/spine-unity/Components/SkeletonUtility/SkeletonUtility.cs @@ -128,12 +128,30 @@ namespace Spine.Unity { public delegate void SkeletonUtilityDelegate (); public event SkeletonUtilityDelegate OnReset; public Transform boneRoot; + /// + /// If true, and are followed + /// by 180 degree rotation. If false, negative Transform scale is used. + /// Note that using negative scale is consistent with previous behaviour (hence the default), + /// however causes serious problems with rigidbodies and physics. Therefore, it is recommended to + /// enable this parameter where possible. When creating hinge chains for a chain of skeleton bones + /// via , it is mandatory to have flipBy180DegreeRotation enabled. + /// + public bool flipBy180DegreeRotation = false; void Update () { var skeleton = skeletonRenderer.skeleton; if (skeleton != null && boneRoot != null) { - boneRoot.localScale = new Vector3(skeleton.ScaleX, skeleton.ScaleY, 1f); - } + + if (flipBy180DegreeRotation) { + boneRoot.localScale = new Vector3(Mathf.Abs(skeleton.ScaleX), Mathf.Abs(skeleton.ScaleY), 1f); + boneRoot.eulerAngles = new Vector3(skeleton.ScaleY > 0 ? 0 : 180, + skeleton.ScaleX > 0 ? 0 : 180, + 0); + } + else { + boneRoot.localScale = new Vector3(skeleton.ScaleX, skeleton.ScaleY, 1f); + } + } } [HideInInspector] public SkeletonRenderer skeletonRenderer; @@ -233,7 +251,10 @@ namespace Spine.Unity { var boneComponents = this.boneComponents; for (int i = 0, n = boneComponents.Count; i < n; i++) { var b = boneComponents[i]; - if (b.bone == null) continue; + if (b.bone == null) { + b.DoUpdate(SkeletonUtilityBone.UpdatePhase.Local); + if (b.bone == null) continue; + } hasOverrideBones |= (b.mode == SkeletonUtilityBone.Mode.Override); hasConstraints |= constraintTargets.Contains(b.bone); }