From 92cacd7e6de4d5315e0ae598ee93683a5556386a Mon Sep 17 00:00:00 2001 From: John Date: Mon, 8 Jan 2018 21:16:20 +0800 Subject: [PATCH] [unity] BoneFollower. Negate rotation from negative scaleX. --- spine-unity/Assets/spine-unity/BoneFollower.cs | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/spine-unity/Assets/spine-unity/BoneFollower.cs b/spine-unity/Assets/spine-unity/BoneFollower.cs index c7d3ea1a2..de68e8c1e 100644 --- a/spine-unity/Assets/spine-unity/BoneFollower.cs +++ b/spine-unity/Assets/spine-unity/BoneFollower.cs @@ -137,7 +137,16 @@ namespace Spine.Unity { if (skeletonTransformIsParent) { // Recommended setup: Use local transform properties if Spine GameObject is the immediate parent thisTransform.localPosition = new Vector3(bone.worldX, bone.worldY, followZPosition ? 0f : thisTransform.localPosition.z); - if (followBoneRotation) thisTransform.localRotation = bone.GetQuaternion(); + if (followBoneRotation) { + var halfRotation = Mathf.Atan2(bone.c, bone.a) * 0.5f; + if (followLocalScale && bone.scaleX < 0) // Negate rotation from negative scaleX. Don't use negative determinant. local scaleY doesn't factor into used rotation. + halfRotation += Mathf.PI * 0.5f; + + var q = default(Quaternion); + q.z = Mathf.Sin(halfRotation); + q.w = Mathf.Cos(halfRotation); + thisTransform.localRotation = q; + } } else { // For special cases: Use transform world properties if transform relationship is complicated Vector3 targetWorldPosition = skeletonTransform.TransformPoint(new Vector3(bone.worldX, bone.worldY, 0f));