From 59fe662bc2606a8b774b8fd0b894cfd9e3f1a7de Mon Sep 17 00:00:00 2001 From: Harald Csaszar Date: Mon, 14 Oct 2019 19:11:52 +0200 Subject: [PATCH] [unity] Fixed SkeletonRagdoll2D incorrect limit angles in Unity 2019.2+. Closes #1521. --- .../SkeletonRagdoll2D.cs | 23 ++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/spine-unity/Assets/Spine Examples/Scripts/Sample Components/SkeletonUtility Modules/SkeletonRagdoll2D.cs b/spine-unity/Assets/Spine Examples/Scripts/Sample Components/SkeletonUtility Modules/SkeletonRagdoll2D.cs index bd8504c4b..a370c23ab 100644 --- a/spine-unity/Assets/Spine Examples/Scripts/Sample Components/SkeletonUtility Modules/SkeletonRagdoll2D.cs +++ b/spine-unity/Assets/Spine Examples/Scripts/Sample Components/SkeletonUtility Modules/SkeletonRagdoll2D.cs @@ -29,6 +29,10 @@ // Contributed by: Mitch Thompson +#if UNITY_2019_2_OR_NEWER +#define HINGE_JOINT_NEW_BEHAVIOUR +#endif + using UnityEngine; using System.Collections; using System.Collections.Generic; @@ -158,9 +162,22 @@ namespace Spine.Unity.Examples { joint.connectedAnchor = localPos; joint.GetComponent().mass = joint.connectedBody.mass * massFalloffFactor; + + #if HINGE_JOINT_NEW_BEHAVIOUR + float referenceAngle = (rbParent.transform.eulerAngles.z - t.eulerAngles.z + 360f) % 360f; + float minAngle = referenceAngle - rotationLimit; + float maxAngle = referenceAngle + rotationLimit; + if (maxAngle > 180f) { + minAngle -= 360f; + maxAngle -= 360f; + } + #else + float minAngle = - rotationLimit; + float maxAngle = rotationLimit; + #endif joint.limits = new JointAngleLimits2D { - min = -rotationLimit, - max = rotationLimit + min = minAngle, + max = maxAngle }; joint.useLimits = true; } @@ -284,7 +301,7 @@ namespace Spine.Unity.Examples { t.parent = transform; t.localPosition = new Vector3(b.WorldX, b.WorldY, 0); t.localRotation = Quaternion.Euler(0, 0, b.WorldRotationX - b.ShearX); - t.localScale = new Vector3(b.WorldScaleX, b.WorldScaleY, 0); + t.localScale = new Vector3(b.WorldScaleX, b.WorldScaleY, 1); // MITCH: You left "todo: proper ragdoll branching" var colliders = AttachBoundingBoxRagdollColliders(b, boneGameObject, skeleton, this.gravityScale);