[unity] Fixed SkeletonRagdoll2D incorrect limit angles in Unity 2019.2+. Closes #1521.

This commit is contained in:
Harald Csaszar 2019-10-14 19:11:52 +02:00
parent 30a460d504
commit 59fe662bc2

View File

@ -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<Rigidbody2D>().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);