void Awake() { if (!blood) { Debug.LogWarning("You need to assign blood prefab in the ragdollHitByBullet script on " + this.name); userNeedsToFixStuff = true; } if (!(ragdollControl = GetComponentInChildren <RagdollControl_AF>())) { Debug.LogWarning("The ragdollHitByBullet script on " + this.name + " requires a RagdollControl script to work"); userNeedsToFixStuff = true; } }
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// void Awake() // Initialize { int i = 0; // Just some counters int j = 0; int k = 0; int l = 0; Time.fixedDeltaTime = fixedDeltaTime; // Set the physics loop update intervall // Debug.Log("The script AnimFollow has set the fixedDeltaTime to " + fixedDeltaTime); // Remove this line if you don't need the "heads up" reciFixedDeltaTime = 1f / fixedDeltaTime; // Cache the reciprocal if (!master) { UnityEngine.Debug.LogWarning("master not assigned in AnimFollow script on " + this.name + "\n"); userNeedsToAssignStuff = true; return; } #if SIMPLEFOOTIK else if (!master.GetComponent <SimpleFootIK_AF>()) { UnityEngine.Debug.LogWarning("Missing script SimpleFootIK_AF on " + master.name + ".\nAdd it or comment out the directive from top line in the AnimFollow script." + "\n"); userNeedsToAssignStuff = true; } #else else if (master.GetComponent <SimpleFootIK_AF>()) { UnityEngine.Debug.LogWarning("There is a SimpleFootIK script on\n" + master.name + " But the directive in the AnimFollow script is commented out"); userNeedsToAssignStuff = true; } #endif else if (hideMaster) { SkinnedMeshRenderer visible; MeshRenderer visible2; if (visible = master.GetComponentInChildren <SkinnedMeshRenderer>()) { visible.enabled = false; SkinnedMeshRenderer[] visibles; visibles = master.GetComponentsInChildren <SkinnedMeshRenderer>(); foreach (SkinnedMeshRenderer visiblen in visibles) { visiblen.enabled = false; } } if (visible2 = master.GetComponentInChildren <MeshRenderer>()) { visible2.enabled = false; MeshRenderer[] visibles2; visibles2 = master.GetComponentsInChildren <MeshRenderer>(); foreach (MeshRenderer visiblen2 in visibles2) { visiblen2.enabled = false; } } } #if RAGDOLLCONTROL if (!(ragdollControl = GetComponent <RagdollControl_AF>())) { UnityEngine.Debug.LogWarning("Missing script RagdollControl on " + this.name + ".\nAdd it or comment out the directive from top line in the AnimFollow script." + "\n"); userNeedsToAssignStuff = true; } #else if (GetComponent <RagdollControl_AF>()) { UnityEngine.Debug.LogWarning("There is a RagdollControl script on\n" + this.name + " But the directive in the AnimFollow script is commented out"); userNeedsToAssignStuff = true; } #endif slaveTransforms = GetComponentsInChildren <Transform>(); // Get all transforms in ragdoll. THE NUMBER OF TRANSFORMS MUST BE EQUAL IN RAGDOLL AS IN MASTER! masterTransforms = master.GetComponentsInChildren <Transform>(); // Get all transforms in master. System.Array.Resize(ref localRotations1, slaveTransforms.Length); System.Array.Resize(ref localRotations2, slaveTransforms.Length); System.Array.Resize(ref rigidbodiesPosToCOM, slaveTransforms.Length); if (!(masterTransforms.Length == slaveTransforms.Length)) { UnityEngine.Debug.LogWarning(this.name + " does not have a valid master.\nMaster transform count does not equal slave transform count." + "\n"); userNeedsToAssignStuff = true; return; } // Resize Arrays (expand #region) #region slaveRigidbodies = GetComponentsInChildren <Rigidbody>(); j = slaveRigidbodies.Length; System.Array.Resize(ref masterRigidTransforms, j); System.Array.Resize(ref slaveRigidTransforms, j); System.Array.Resize(ref maxTorqueProfile, j); System.Array.Resize(ref maxForceProfile, j); System.Array.Resize(ref maxJointTorqueProfile, j); System.Array.Resize(ref jointDampingProfile, j); System.Array.Resize(ref PTorqueProfile, j); System.Array.Resize(ref PForceProfile, j); System.Array.Resize(ref forceErrorWeightProfile, j); System.Array.Resize(ref torqueLastError, j); System.Array.Resize(ref forceLastError, j); System.Array.Resize(ref lastMasterRotation, j); System.Array.Resize(ref lastSlaveRotation, j); System.Array.Resize(ref lastSlavelocalRotation, j); System.Array.Resize(ref lastMasterPosition, j); System.Array.Resize(ref lastSlavePosition, j); System.Array.Resize(ref startLocalRotation, j); System.Array.Resize(ref configurableJoints, j); System.Array.Resize(ref localToJointSpace, j); #endregion // int j = 0; // foreach (Transform ragdollRigidTransform in ragdollRigidTransforms) // Set up configurable joints and rigidbodies j = 0; foreach (Transform slaveTransform in slaveTransforms) // Sort the transform arrays { if (slaveTransform.GetComponent <Rigidbody>()) { slaveRigidTransforms[j] = slaveTransform; masterRigidTransforms[j] = masterTransforms[i]; if (slaveTransform.GetComponent <ConfigurableJoint>()) { configurableJoints[j] = slaveTransform.GetComponent <ConfigurableJoint>(); Vector3 forward = Vector3.Cross(configurableJoints[j].axis, configurableJoints[j].secondaryAxis); Vector3 up = configurableJoints[j].secondaryAxis; localToJointSpace[j] = Quaternion.LookRotation(forward, up); startLocalRotation[j] = slaveTransform.localRotation * localToJointSpace[j]; jointDrive = configurableJoints[j].slerpDrive; jointDrive.mode = JointDriveMode.Position; configurableJoints[j].slerpDrive = jointDrive; l++; } else if (j > 0) { UnityEngine.Debug.LogWarning("Rigidbody " + slaveTransform.name + " on " + this.name + " is not connected to a configurable joint" + "\n"); userNeedsToAssignStuff = true; return; } rigidbodiesPosToCOM[j] = Quaternion.Inverse(slaveTransform.rotation) * (slaveTransform.GetComponent <Rigidbody>().worldCenterOfMass - slaveTransform.position); j++; } else { bool excludeBool = false; foreach (Transform exclude in slaveExcludeTransforms) { if (slaveTransform == exclude) { excludeBool = true; break; } } if (!excludeBool) { slaveTransforms[k] = slaveTransform; masterTransforms[k] = masterTransforms[i]; localRotations1[k] = slaveTransform.localRotation; k++; } } i++; } localRotations2 = localRotations1; System.Array.Resize(ref masterTransforms, k); System.Array.Resize(ref slaveTransforms, k); System.Array.Resize(ref localRotations1, k); System.Array.Resize(ref localRotations2, k); if (l == 0) { UnityEngine.Debug.LogWarning("There are no configurable joints on the ragdoll " + this.name + "\nDrag and drop the ReplaceJoints script on the ragdoll." + "\n"); userNeedsToAssignStuff = true; return; } else { SetJointTorque(maxJointTorque); EnableJointLimits(false); } if (slaveRigidTransforms.Length == 0) { UnityEngine.Debug.LogWarning("There are no rigid body components on the ragdoll " + this.name + "\n"); } else if (slaveRigidTransforms.Length < 12) { UnityEngine.Debug.Log("This version of AnimFollow works better with one extra colleder in the spine on " + this.name + "\n"); } if (PTorqueProfile[PTorqueProfile.Length - 1] == 0f) { UnityEngine.Debug.Log("The last entry in the PTorqueProfile is zero on " + this.name + ".\nIs that intentional?\nDrop ResizeProfiles on the ragdoll and adjust the values." + "\n"); } if (slaveExcludeTransforms.Length == 0) { UnityEngine.Debug.Log("Should you not assign some slaveExcludeTransforms to the AnimFollow script on " + this.name + "\n"); } }
void OnEnable() { ragdollControl = transform.root.GetComponentInChildren <RagdollControl_AF>(); ignoreCollidersWithTag = ragdollControl.ignoreCollidersWithTag; }