From 45d8adb64c83c462a4df69de7cbb439d4dd164c8 Mon Sep 17 00:00:00 2001 From: Fenrisul Date: Sat, 16 May 2015 06:20:20 -0700 Subject: [PATCH] [Unity] Repaired misc Ragdoll things. --- .../Assets/Examples/Scenes/Ragdoll.unity | Bin 49612 -> 49644 bytes .../Examples/Scripts/DynamicSpineBone.cs | 97 ------------------ .../Examples/Scripts/DynamicSpineBone.cs.meta | 10 -- .../Examples/Scripts/RaggedySpineboy.cs | 3 +- .../Examples/Spine/Raggedy Spineboy.prefab | Bin 13928 -> 13960 bytes .../Editor/SkeletonRagdoll2DInspector.cs | 13 ++- .../Editor/SkeletonRagdollInspector.cs | 10 +- .../spine-unity/Ragdoll/SkeletonRagdoll.cs | 46 +++++++-- .../spine-unity/Ragdoll/SkeletonRagdoll2D.cs | 59 ++++++++--- 9 files changed, 103 insertions(+), 135 deletions(-) delete mode 100644 spine-unity/Assets/Examples/Scripts/DynamicSpineBone.cs delete mode 100644 spine-unity/Assets/Examples/Scripts/DynamicSpineBone.cs.meta diff --git a/spine-unity/Assets/Examples/Scenes/Ragdoll.unity b/spine-unity/Assets/Examples/Scenes/Ragdoll.unity index b35ed755488172a89ef953b1ed78e1ff9e326423..2403edf40c01183da96d78f611cdc259d1877cdc 100644 GIT binary patch delta 1039 zcmaiyUr1AN6vxkRn|CWrN1D3%?*?mT2qg)LT23kR!Dy98$R0LKSvXqhf`UN99`_I& zp;#^FzcLka{rV$?H1ov=d)J2`sD}azd(K$j>vm~-@&|`|&gXZ|{hs^fu8kNsM~qgY zNHfv$CK2sH?u}dPRB<5g{$%7Yd(G13_$v6QvzS%I&R%DpaB@7i07S_T`LFi$U+Wzl zBol_K_;;<1-#Yj6s8YyV{Yu_IFc>=LOJ7&x+MbW9%@+s+`}*2^J)t1~blUl|vxtk# z+K8F+s?2=GTqvunx&y+`_gD(QtRGzwLmwu;U3^$fbOTZ%9SJaN2~iX3lj&FnbAx$N zqkShnf-QhKP#;Xk3fMYWCu(hdEh3?YOUGn4R@WZHu+<0)?AkRlO3?heXqmAr}SY#l&CWM7s z=FiIEv9Lj$;JZ%?q&iV#RMb|Y*;a0v?of$bE^SksQ$(>ABDM99BJf*lXSi9;OkWo4 zS}Npl%pvQaEeMmQ&zmz-`?N&s>X^K6TyT7%fD=>gsq5|MN1Q1YtwB2`gs1VvPM$f) zp6Qyp-L}wQ(4FxDo}ayw604c>q>}KQBbB_G3k!>EnV-zjtl&U2S0<$2pzfw4+utY# j-JaS=i3}|MH}PGr*fGKKa#6_G``+Vd5K(0{#`NT$!!&_VHcW7ICV)&Bxq4$^~qRlDwe?_V9lu2 z+o%x=R5$%9q(O?J&_o^pMv92sV1G6@H@mSu1j{KV8bba%#lm1W!DKK^_z~DQFgutg zJOXAc$rO%)b%LoHwa`!8XcTY_@Fd{hlt|HYYB5_gT_^^-4VLag3D_E#jJ?`0RQrQbEr7|WHDL+NjO+h*LHxYe zuM^#&4>~6ChHwp+LpdTCjx$DFiJcaak)Vzp;?c+X!Z})?mo`oiU9aQq6E2%N5RucV zuB&m^QKHE41frp1>MB+yS{bhon|Lf@7p;@C%%FZwJom}?4mDAGTw@If8Gk#P&)3K6 zldp@X_BoO&YJ>V15bZTHi9CHHADF19+G+~zfVQ*)czkLgDdw7PPbRTxdop=H9b_bw z*jQF#?3@=1Oqic`>bAaaWbkXOY;Y< diff --git a/spine-unity/Assets/Examples/Scripts/DynamicSpineBone.cs b/spine-unity/Assets/Examples/Scripts/DynamicSpineBone.cs deleted file mode 100644 index bfaa254e7..000000000 --- a/spine-unity/Assets/Examples/Scripts/DynamicSpineBone.cs +++ /dev/null @@ -1,97 +0,0 @@ -/****************************************************************************** - * Spine Runtimes Software License - * Version 2.3 - * - * Copyright (c) 2013-2015, Esoteric Software - * All rights reserved. - * - * You are granted a perpetual, non-exclusive, non-sublicensable and - * non-transferable license to use, install, execute and perform the Spine - * Runtimes Software (the "Software") and derivative works solely for personal - * or internal use. Without the written permission of Esoteric Software (see - * Section 2 of the Spine Software License Agreement), you may not (a) modify, - * translate, adapt or otherwise create derivative works, improvements of the - * Software or develop new applications using the Software or (b) remove, - * delete, alter or obscure any trademarks or any copyright, trademark, patent - * or other intellectual property or proprietary rights notices on or in the - * Software, including any copy thereof. Redistributions in binary or source - * form must include this license and terms. - * - * THIS SOFTWARE IS PROVIDED BY ESOTERIC SOFTWARE "AS IS" AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF - * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO - * EVENT SHALL ESOTERIC SOFTWARE BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; - * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR - * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF - * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - *****************************************************************************/ - -using UnityEngine; -using System.Collections; - -public class DynamicSpineBone : MonoBehaviour { - - public Transform speedReference; - - [SpineBone] - public string boneName; - - [Range(-90, 90)] - public float minRotation = -45; - [Range(-90, 90)] - public float maxRotation = 45; - - [Range(-2000, 2000)] - public float rotationFactor = 300; - - [Range(5, 30)] - public float returnSpeed = 10; - - [Range(100, 1000)] - public float boneSpeed = 300; - - public float returnThreshhold = 0.01f; - - public bool useAcceleration; - - - SkeletonAnimation skeletonAnimation; - float goalRotation; - Spine.Bone bone; - Vector3 velocity; - Vector3 acceleration; - Vector3 lastPosition; - - void Start() { - if (speedReference == null) - speedReference = transform; - - skeletonAnimation = GetComponent(); - bone = SpineBone.GetBone(boneName, skeletonAnimation); - skeletonAnimation.UpdateLocal += UpdateLocal; - lastPosition = speedReference.position; - } - - void FixedUpdate() { - acceleration = (speedReference.position - lastPosition) - velocity; - velocity = speedReference.position - lastPosition; - lastPosition = speedReference.position; - } - - void UpdateLocal(SkeletonRenderer renderer) { - Vector3 vec = useAcceleration ? acceleration : velocity; - - if (Mathf.Abs(vec.x) < returnThreshhold) - goalRotation = Mathf.Lerp(goalRotation, 0, returnSpeed * Time.deltaTime); - else - goalRotation += vec.x * rotationFactor * Time.deltaTime * (bone.WorldFlipX ? -1 : 1); - - goalRotation = Mathf.Clamp(goalRotation, minRotation, maxRotation); - - bone.Rotation = Mathf.Lerp(bone.Rotation, bone.Rotation + goalRotation, boneSpeed * Time.deltaTime); - - } -} diff --git a/spine-unity/Assets/Examples/Scripts/DynamicSpineBone.cs.meta b/spine-unity/Assets/Examples/Scripts/DynamicSpineBone.cs.meta deleted file mode 100644 index bc05f26e6..000000000 --- a/spine-unity/Assets/Examples/Scripts/DynamicSpineBone.cs.meta +++ /dev/null @@ -1,10 +0,0 @@ -fileFormatVersion: 2 -guid: 7dae3f4db9a24bf4abe2059526bfd689 -MonoImporter: - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: diff --git a/spine-unity/Assets/Examples/Scripts/RaggedySpineboy.cs b/spine-unity/Assets/Examples/Scripts/RaggedySpineboy.cs index eea04f694..f15e773fc 100644 --- a/spine-unity/Assets/Examples/Scripts/RaggedySpineboy.cs +++ b/spine-unity/Assets/Examples/Scripts/RaggedySpineboy.cs @@ -48,7 +48,6 @@ public class RaggedySpineboy : MonoBehaviour { Vector3 estimatedPos = ragdoll.EstimatedSkeletonPosition; Vector3 rbPosition = ragdoll.RootRigidbody.position; - Ray ray = new Ray(rbPosition, estimatedPos - rbPosition); Vector3 skeletonPoint = estimatedPos; RaycastHit2D hit = Physics2D.Raycast((Vector2)rbPosition, (Vector2)(estimatedPos - rbPosition), Vector3.Distance(estimatedPos, rbPosition), groundMask); if (hit.collider != null) @@ -69,7 +68,7 @@ public class RaggedySpineboy : MonoBehaviour { float t = 0; while (t < 0.5f) { - if (ragdoll.RootRigidbody.velocity.magnitude > 0.06f) + if (ragdoll.RootRigidbody.velocity.magnitude > 0.09f) t = 0; else t += Time.deltaTime; diff --git a/spine-unity/Assets/Examples/Spine/Raggedy Spineboy.prefab b/spine-unity/Assets/Examples/Spine/Raggedy Spineboy.prefab index 618b8cd95ff086851dcd42752a28327710eb70fa..3828cb89ebb35be4ebfe86f3ee78726c2194355f 100644 GIT binary patch delta 259 zcmaEn(~&E{z+kM*z+l$Fz`(!>WIJpW&|_s3-579|d2&57`(|Oz$BdKb39?Pr=N4pC zo$Sc1&ZsuITTqg}BqK99J1@1kn1KbTRUIfJJb5*@#N?|&B7A8%`H3YAMfv$9zKO-f zllO5;%0h&4fn2x5oSgi$G`Ga$lKdjDW-YMh>)c|D+8`D`RBdJjSXKulwpp1cK#ehD za*5HN$-2hJ*%=rV9JsDKZ~kq3mr;R%!NGwM=m;RNV_;a|2$XbEWn;952sPMG7BE$r bEMq3crr^ZDu*zw2f~nNx05h)131%Ds91%ix delta 253 zcmeCkeUT%;z+lYAz+jfaz`(!>WGieG&|_s3*%)w^d2&57`(|Oz$BdKhgxI7~^AeMC zQoZss^Gclab8<3^GxPHp7=gM}CqL%WVpN;Fkz07OBDaW^I#3J*KynP8AcBD*Ehj&* zgdrt0EwMDGBqSp}UEKxCczW@(eVj51(57#tix^w~2$b_@&)96|OmFf`at hZZH*@>;S|zW>RdwoER9YoPk18lMBqaCO4RI007}GLHqy! diff --git a/spine-unity/Assets/spine-unity/Ragdoll/Editor/SkeletonRagdoll2DInspector.cs b/spine-unity/Assets/spine-unity/Ragdoll/Editor/SkeletonRagdoll2DInspector.cs index f059aae31..87c3da693 100644 --- a/spine-unity/Assets/spine-unity/Ragdoll/Editor/SkeletonRagdoll2DInspector.cs +++ b/spine-unity/Assets/spine-unity/Ragdoll/Editor/SkeletonRagdoll2DInspector.cs @@ -10,20 +10,21 @@ using System.Collections.Generic; [CustomEditor(typeof(SkeletonRagdoll2D))] public class SkeletonRagdoll2DInspector : Editor { - SerializedProperty startingBoneName, stopBoneNames, applyOnStart, pinStartBone, enableJointCollision, gravityScale, disableIK, defaultThickness, rotationLimit, colliderLayer, mix; + SerializedProperty startingBoneName, stopBoneNames, applyOnStart, pinStartBone, enableJointCollision, gravityScale, disableIK, thickness, rotationLimit, colliderLayer, mix, rootMass, massFalloffFactor; void OnEnable () { startingBoneName = serializedObject.FindProperty("startingBoneName"); stopBoneNames = serializedObject.FindProperty("stopBoneNames"); applyOnStart = serializedObject.FindProperty("applyOnStart"); pinStartBone = serializedObject.FindProperty("pinStartBone"); - enableJointCollision = serializedObject.FindProperty("enableJointCollision"); gravityScale = serializedObject.FindProperty("gravityScale"); disableIK = serializedObject.FindProperty("disableIK"); - defaultThickness = serializedObject.FindProperty("defaultThickness"); + thickness = serializedObject.FindProperty("thickness"); rotationLimit = serializedObject.FindProperty("rotationLimit"); colliderLayer = serializedObject.FindProperty("colliderLayer"); mix = serializedObject.FindProperty("mix"); + rootMass = serializedObject.FindProperty("rootMass"); + massFalloffFactor = serializedObject.FindProperty("massFalloffFactor"); } public override void OnInspectorGUI () { @@ -31,13 +32,15 @@ public class SkeletonRagdoll2DInspector : Editor { EditorGUILayout.PropertyField(stopBoneNames, true); EditorGUILayout.PropertyField(applyOnStart); EditorGUILayout.PropertyField(pinStartBone); - EditorGUILayout.PropertyField(enableJointCollision); EditorGUILayout.PropertyField(gravityScale); EditorGUILayout.PropertyField(disableIK); - EditorGUILayout.PropertyField(defaultThickness); + EditorGUILayout.PropertyField(thickness); EditorGUILayout.PropertyField(rotationLimit); + EditorGUILayout.PropertyField(rootMass); + EditorGUILayout.PropertyField(massFalloffFactor); colliderLayer.intValue = EditorGUILayout.LayerField(colliderLayer.displayName, colliderLayer.intValue); EditorGUILayout.PropertyField(mix); + serializedObject.ApplyModifiedProperties(); } diff --git a/spine-unity/Assets/spine-unity/Ragdoll/Editor/SkeletonRagdollInspector.cs b/spine-unity/Assets/spine-unity/Ragdoll/Editor/SkeletonRagdollInspector.cs index a92f570e2..af1627af4 100644 --- a/spine-unity/Assets/spine-unity/Ragdoll/Editor/SkeletonRagdollInspector.cs +++ b/spine-unity/Assets/spine-unity/Ragdoll/Editor/SkeletonRagdollInspector.cs @@ -10,7 +10,7 @@ using System.Collections.Generic; [CustomEditor(typeof(SkeletonRagdoll))] public class SkeletonRagdollInspector : Editor { - SerializedProperty startingBoneName, stopBoneNames, applyOnStart, pinStartBone, enableJointCollision, useGravity, disableIK, defaultThickness, rotationLimit, colliderLayer, mix; + SerializedProperty startingBoneName, stopBoneNames, applyOnStart, pinStartBone, enableJointCollision, useGravity, disableIK, thickness, rotationLimit, colliderLayer, mix, rootMass, massFalloffFactor; void OnEnable () { startingBoneName = serializedObject.FindProperty("startingBoneName"); @@ -20,10 +20,12 @@ public class SkeletonRagdollInspector : Editor { enableJointCollision = serializedObject.FindProperty("enableJointCollision"); useGravity = serializedObject.FindProperty("useGravity"); disableIK = serializedObject.FindProperty("disableIK"); - defaultThickness = serializedObject.FindProperty("defaultThickness"); + thickness = serializedObject.FindProperty("thickness"); rotationLimit = serializedObject.FindProperty("rotationLimit"); colliderLayer = serializedObject.FindProperty("colliderLayer"); mix = serializedObject.FindProperty("mix"); + rootMass = serializedObject.FindProperty("rootMass"); + massFalloffFactor = serializedObject.FindProperty("massFalloffFactor"); } public override void OnInspectorGUI () { @@ -34,8 +36,10 @@ public class SkeletonRagdollInspector : Editor { EditorGUILayout.PropertyField(enableJointCollision); EditorGUILayout.PropertyField(useGravity); EditorGUILayout.PropertyField(disableIK); - EditorGUILayout.PropertyField(defaultThickness); + EditorGUILayout.PropertyField(thickness); EditorGUILayout.PropertyField(rotationLimit); + EditorGUILayout.PropertyField(rootMass); + EditorGUILayout.PropertyField(massFalloffFactor); colliderLayer.intValue = EditorGUILayout.LayerField(colliderLayer.displayName, colliderLayer.intValue); EditorGUILayout.PropertyField(mix); diff --git a/spine-unity/Assets/spine-unity/Ragdoll/SkeletonRagdoll.cs b/spine-unity/Assets/spine-unity/Ragdoll/SkeletonRagdoll.cs index ac43ad1cd..24cb9f6c1 100644 --- a/spine-unity/Assets/spine-unity/Ragdoll/SkeletonRagdoll.cs +++ b/spine-unity/Assets/spine-unity/Ragdoll/SkeletonRagdoll.cs @@ -28,9 +28,13 @@ public class SkeletonRagdoll : MonoBehaviour { [Tooltip("Warning! You will have to re-enable and tune mix values manually if attempting to remove the ragdoll system.")] public bool disableIK = true; [Tooltip("If no BoundingBox Attachment is attached to a bone, this becomes the default Width or Radius of a Bone's ragdoll Rigidbody")] - public float defaultThickness = 0.125f; + public float thickness = 0.125f; [Tooltip("Default rotational limit value. Min is negative this value, Max is this value.")] public float rotationLimit = 20; + public float rootMass = 20; + [Tooltip("If your ragdoll seems unstable or uneffected by limits, try lowering this value.")] + [Range(0.01f, 1f)] + public float massFalloffFactor = 0.4f; [Tooltip("The layer assigned to all of the rigidbody parts.")] public int colliderLayer = 0; [Range(0, 1)] @@ -106,6 +110,34 @@ public class SkeletonRagdoll : MonoBehaviour { foreach (Transform t in boneTable.Values) { t.position -= offset; } + + UpdateWorld(null); + skeleton.UpdateWorldTransform(); + } + + public Rigidbody[] GetRigidbodyArray () { + if (!isActive) + return new Rigidbody[0]; + + Rigidbody[] arr = new Rigidbody[boneTable.Count]; + int i = 0; + foreach(Transform t in boneTable.Values){ + arr[i] = t.GetComponent(); + i++; + } + + return arr; + } + + public Rigidbody GetRigidbody (string boneName) { + var bone = skeleton.FindBone(boneName); + if (bone == null) + return null; + + if (boneTable.ContainsKey(bone)) + return boneTable[bone].GetComponent(); + + return null; } public void Remove () { @@ -131,6 +163,8 @@ public class SkeletonRagdoll : MonoBehaviour { rootRigidbody = boneTable[ragdollRootBone].GetComponent(); rootRigidbody.isKinematic = pinStartBone; + rootRigidbody.mass = rootMass; + List boneColliders = new List(); foreach (var pair in boneTable) { @@ -170,7 +204,7 @@ public class SkeletonRagdoll : MonoBehaviour { localPos.x *= 1; joint.connectedAnchor = localPos; joint.axis = Vector3.forward; - joint.GetComponent().mass = joint.connectedBody.mass * 0.75f; + joint.GetComponent().mass = joint.connectedBody.mass * massFalloffFactor; JointLimits limits = new JointLimits(); limits.min = -rotationLimit; limits.max = rotationLimit; @@ -182,6 +216,7 @@ public class SkeletonRagdoll : MonoBehaviour { for (int x = 0; x < boneColliders.Count; x++) { for (int y = 0; y < boneColliders.Count; y++) { + if (x == y) continue; Physics.IgnoreCollision(boneColliders[x], boneColliders[y]); } } @@ -240,13 +275,13 @@ public class SkeletonRagdoll : MonoBehaviour { //physics if (colliders.Count == 0) { var ball = go.AddComponent(); - ball.radius = defaultThickness / 2f; + ball.radius = thickness / 2f; } } else { //physics if (colliders.Count == 0) { var box = go.AddComponent(); - box.size = new Vector3(length, defaultThickness, defaultThickness); + box.size = new Vector3(length, thickness, thickness); box.center = new Vector3((b.WorldFlipX ? -length : length) / 2, 0); } } @@ -254,7 +289,6 @@ public class SkeletonRagdoll : MonoBehaviour { var rb = go.AddComponent(); rb.constraints = RigidbodyConstraints.FreezePositionZ; foreach (Bone child in b.Children) { - RecursivelyCreateBoneProxies(child); } } @@ -281,7 +315,7 @@ public class SkeletonRagdoll : MonoBehaviour { continue; var collider = go.AddComponent(); - var bounds = SkeletonUtility.GetBoundingBoxBounds((BoundingBoxAttachment)a, defaultThickness); + var bounds = SkeletonUtility.GetBoundingBoxBounds((BoundingBoxAttachment)a, thickness); collider.center = bounds.center; collider.size = bounds.size; diff --git a/spine-unity/Assets/spine-unity/Ragdoll/SkeletonRagdoll2D.cs b/spine-unity/Assets/spine-unity/Ragdoll/SkeletonRagdoll2D.cs index 88eba0990..690e10dd2 100644 --- a/spine-unity/Assets/spine-unity/Ragdoll/SkeletonRagdoll2D.cs +++ b/spine-unity/Assets/spine-unity/Ragdoll/SkeletonRagdoll2D.cs @@ -22,15 +22,17 @@ public class SkeletonRagdoll2D : MonoBehaviour { public bool applyOnStart; [Tooltip("Set RootRigidbody IsKinematic to true when Apply is called.")] public bool pinStartBone; - [Tooltip("Enable Collision between adjacent ragdoll elements (IE: Neck and Head)")] - public bool enableJointCollision; public float gravityScale = 1; [Tooltip("Warning! You will have to re-enable and tune mix values manually if attempting to remove the ragdoll system.")] public bool disableIK = true; [Tooltip("If no BoundingBox Attachment is attached to a bone, this becomes the default Width or Radius of a Bone's ragdoll Rigidbody")] - public float defaultThickness = 0.125f; + public float thickness = 0.125f; [Tooltip("Default rotational limit value. Min is negative this value, Max is this value.")] public float rotationLimit = 20; + public float rootMass = 20; + [Tooltip("If your ragdoll seems unstable or uneffected by limits, try lowering this value.")] + [Range(0.01f, 1f)] + public float massFalloffFactor = 0.4f; [Tooltip("The layer assigned to all of the rigidbody parts.")] public int colliderLayer = 0; [Range(0, 1)] @@ -110,7 +112,31 @@ public class SkeletonRagdoll2D : MonoBehaviour { UpdateWorld(null); skeleton.UpdateWorldTransform(); - //skeletonAnim.LateUpdate(); + } + + public Rigidbody2D[] GetRigidbodyArray () { + if (!isActive) + return new Rigidbody2D[0]; + + Rigidbody2D[] arr = new Rigidbody2D[boneTable.Count]; + int i = 0; + foreach (Transform t in boneTable.Values) { + arr[i] = t.GetComponent(); + i++; + } + + return arr; + } + + public Rigidbody2D GetRigidbody (string boneName) { + var bone = skeleton.FindBone(boneName); + if (bone == null) + return null; + + if (boneTable.ContainsKey(bone)) + return boneTable[bone].GetComponent(); + + return null; } public void Remove () { @@ -135,6 +161,7 @@ public class SkeletonRagdoll2D : MonoBehaviour { rootRigidbody = boneTable[ragdollRootBone].GetComponent(); rootRigidbody.isKinematic = pinStartBone; + rootRigidbody.mass = rootMass; List boneColliders = new List(); @@ -174,17 +201,18 @@ public class SkeletonRagdoll2D : MonoBehaviour { Vector3 localPos = parentTransform.InverseTransformPoint(t.position); localPos.x *= 1; joint.connectedAnchor = localPos; - joint.GetComponent().mass = joint.connectedBody.mass * 0.75f; + joint.GetComponent().mass = joint.connectedBody.mass * massFalloffFactor; JointAngleLimits2D limits = new JointAngleLimits2D(); limits.min = -rotationLimit; limits.max = rotationLimit; joint.limits = limits; - joint.useLimits = enableJointCollision; + joint.useLimits = true; } } for (int x = 0; x < boneColliders.Count; x++) { for (int y = 0; y < boneColliders.Count; y++) { + if (x == y) continue; Physics2D.IgnoreCollision(boneColliders[x], boneColliders[y]); } } @@ -245,13 +273,13 @@ public class SkeletonRagdoll2D : MonoBehaviour { //physics if (colliders.Count == 0) { var circle = go.AddComponent(); - circle.radius = defaultThickness / 2f; + circle.radius = thickness / 2f; } } else { //physics if (colliders.Count == 0) { var box = go.AddComponent(); - box.size = new Vector2(length, defaultThickness); + box.size = new Vector2(length, thickness); #if UNITY_5_0 box.offset = new Vector2((b.WorldFlipX ? -length : length) / 2, 0); #else @@ -330,8 +358,15 @@ public class SkeletonRagdoll2D : MonoBehaviour { flipY = parentBone.WorldFlipY; } else { - flipX = b.worldFlipX; - flipY = b.WorldFlipY; + parentBone = b.Parent; + parentTransform = ragdollRoot; + if (b.Parent != null) { + flipX = b.worldFlipX; + flipY = b.WorldFlipY; + } else { + flipX = b.Skeleton.FlipX; + flipY = b.Skeleton.FlipY; + } } flip = flipX ^ flipY; @@ -378,10 +413,10 @@ public class SkeletonRagdoll2D : MonoBehaviour { void OnDrawGizmosSelected () { if (isActive) { - Gizmos.DrawWireSphere(transform.position, defaultThickness * 1.2f); + Gizmos.DrawWireSphere(transform.position, thickness * 1.2f); Vector3 newTransformPos = rootRigidbody.position - rootOffset; Gizmos.DrawLine(transform.position, newTransformPos); - Gizmos.DrawWireSphere(newTransformPos, defaultThickness * 1.2f); + Gizmos.DrawWireSphere(newTransformPos, thickness * 1.2f); } }