protected override bool DetectSetup() { if (lid == null || body == null) { return(false); } finalDirection = (direction == Direction.autodetect) ? DetectDirection() : direction; if (finalDirection == Direction.autodetect) { return(false); } Bounds lidBounds = VRTK_SharedMethods.GetBounds(lid.transform, transform); // determin sub-direction depending on handle if (handle) { Bounds handleBounds = VRTK_SharedMethods.GetBounds(handle.transform, transform); switch (finalDirection) { case Direction.x: subDirection = (handleBounds.center.x > lidBounds.center.x) ? -1 : 1; break; case Direction.y: subDirection = (handleBounds.center.y > lidBounds.center.y) ? -1 : 1; break; case Direction.z: subDirection = (handleBounds.center.z > lidBounds.center.z) ? -1 : 1; break; } // handle should be outside lid hierarchy, otherwise anchor-by-bounds calculation is off if (handle.transform.IsChildOf(lid.transform)) { return(false); } } else { subDirection = -1; } if (lidJointCreated) { lidJoint.useLimits = true; lidJoint.enableCollision = true; JointLimits limits = lidJoint.limits; switch (finalDirection) { case Direction.x: lidJoint.anchor = new Vector3(subDirection * lidBounds.extents.x, 0, 0); lidJoint.axis = new Vector3(0, 0, 1); if (subDirection > 0) { limits.min = -maxAngle; limits.max = minAngle; } else { limits.min = minAngle; limits.max = maxAngle; } break; case Direction.y: lidJoint.anchor = new Vector3(0, subDirection * lidBounds.extents.y, 0); lidJoint.axis = new Vector3(0, 1, 0); if (subDirection > 0) { limits.min = -maxAngle; limits.max = minAngle; } else { limits.min = minAngle; limits.max = maxAngle; } break; case Direction.z: lidJoint.anchor = new Vector3(0, 0, subDirection * lidBounds.extents.z); lidJoint.axis = new Vector3(1, 0, 0); if (subDirection < 0) { limits.min = -maxAngle; limits.max = minAngle; } else { limits.min = minAngle; limits.max = maxAngle; } break; } lidJoint.limits = limits; } return(true); }
void Create_Suspension_Arm(string direction, int number) { // Create gameobject & Set parent GameObject armObject = new GameObject("Suspension_" + direction + "_" + number); armObject.transform.parent = thisTransform; // Set position. Vector3 pos; pos.x = 0.0f; pos.z = -SpacingProp.floatValue * (number - 1); pos.y = Sus_DistanceProp.floatValue / 2.0f; if (direction == "R") { pos.y *= -1.0f; } armObject.transform.localPosition = pos; // Set rotation. if (Set_IndividuallyProp.boolValue) { armObject.transform.localRotation = Quaternion.Euler(0.0f, Sus_AnglesProp.GetArrayElementAtIndex(number - 1).floatValue, -90.0f); } else { armObject.transform.localRotation = Quaternion.Euler(0.0f, Sus_AngleProp.floatValue, -90.0f); } // Mesh if (direction == "L") // Left { if (Sus_L_MeshProp.objectReferenceValue) { MeshFilter meshFilter; meshFilter = armObject.AddComponent <MeshFilter> (); meshFilter.mesh = Sus_L_MeshProp.objectReferenceValue as Mesh; } } else // Right { if (Sus_R_MeshProp.objectReferenceValue) { MeshFilter meshFilter; meshFilter = armObject.AddComponent <MeshFilter> (); meshFilter.mesh = Sus_R_MeshProp.objectReferenceValue as Mesh; } } MeshRenderer meshRenderer = armObject.AddComponent <MeshRenderer> (); Material[] materials = new Material [Sus_Materials_NumProp.intValue]; for (int i = 0; i < materials.Length; i++) { materials [i] = Sus_MaterialsProp.GetArrayElementAtIndex(i).objectReferenceValue as Material; } meshRenderer.materials = materials; // Rigidbody Rigidbody rigidbody = armObject.AddComponent <Rigidbody> (); rigidbody.mass = Sus_MassProp.floatValue; // HingeJoint HingeJoint hingeJoint = armObject.AddComponent <HingeJoint> (); hingeJoint.connectedBody = thisTransform.parent.gameObject.GetComponent <Rigidbody> (); //MainBody's Rigidbody. hingeJoint.anchor = new Vector3(0.0f, 0.0f, Sus_AnchorProp.floatValue); hingeJoint.axis = new Vector3(1.0f, 0.0f, 0.0f); hingeJoint.useSpring = true; JointSpring jointSpring = hingeJoint.spring; jointSpring.spring = Sus_SpringProp.floatValue; jointSpring.damper = Sus_DamperProp.floatValue; if (Set_IndividuallyProp.boolValue) { jointSpring.targetPosition = Sus_TargetProp.floatValue + Sus_AnglesProp.GetArrayElementAtIndex(number - 1).floatValue; } else { jointSpring.targetPosition = Sus_TargetProp.floatValue + Sus_AngleProp.floatValue; } hingeJoint.spring = jointSpring; hingeJoint.useLimits = true; JointLimits jointLimits = hingeJoint.limits; if (Set_IndividuallyProp.boolValue) { jointLimits.max = Sus_Forward_LimitProp.floatValue + Sus_AnglesProp.GetArrayElementAtIndex(number - 1).floatValue; jointLimits.min = -(Sus_Backward_LimitProp.floatValue - Sus_AnglesProp.GetArrayElementAtIndex(number - 1).floatValue); } else { jointLimits.max = Sus_Forward_LimitProp.floatValue + Sus_AngleProp.floatValue; jointLimits.min = -(Sus_Backward_LimitProp.floatValue - Sus_AngleProp.floatValue); } hingeJoint.limits = jointLimits; // Reinforce SphereCollider SphereCollider sphereCollider = armObject.AddComponent <SphereCollider> (); sphereCollider.radius = Reinforce_RadiusProp.floatValue; // Set Layer armObject.layer = Layer_Settings_CS.Reinforce_Layer; }
// void Generate() { LineRenderer lineRenderer = GetComponent <LineRenderer>(); lineRenderer.SetPosition(0, Camera.main.ScreenToWorldPoint(Input.mousePosition)); // If the left mouse button is clicked for the first time if (Input.GetKeyUp(KeyCode.Mouse0) && firstClick == false) { lineRenderer.positionCount = 2; // print ("enters loop start"); // Store the position as the start point startPoint = hit.point; // print (startPoint + " " + hit.point); lineRenderer.SetPosition(1, startPoint); firstClick = true; return; } // // // If the left mouse button is clicked a second time if (Input.GetKeyUp(KeyCode.Mouse0) && firstClick == true) { lineRenderer.SetPosition(0, endPoint); lineRenderer.positionCount = 1; // print ("enters loop second"); // Store the mouse position as the end point endPoint = hit.point; // print (endPoint + " " + hit.point); // Calculate the distance between the two points middle = (startPoint - endPoint) / 2; print(middle); // Calculate the vector from start point to end point Vector3 direction = endPoint - startPoint; // Calculate the angle of the direction vector by comparing it to our reference vector float angle = Vector3.Angle(direction, angleReference); // // If the horizontal position of the start point is smaller than the one of the end point if (startPoint.x < endPoint.x) { // If the angle of the vector is less than 90degrees if (angle < 90) { // Modify the Hingejoints limits values limitMinAngle = -90; limitMaxAngle = 0; } // If the angle of the vector is more or equal than 90degrees if (angle >= 90) { // Modify the Hingejoints limits values angle = -angle; limitMinAngle = 0; limitMaxAngle = 90; } // Instantiate in the Flippers List a left Flipper object at the click position, with the angle of the vector flippersList.Add((GameObject)Instantiate(leftFlipper, new Vector3(hit.point.x + 2 * middle.x, hit.point.y + middle.y, channel.transform.position.z), Quaternion.Euler(0, 0, angle))); // Add one to the amount of Flippers amountFlippers++; // Modify the HingeJoint values to the correct ones HingeJoint hj = flippersList[amountFlippers].GetComponent <HingeJoint>(); JointLimits limits = hj.limits; limits.min = limitMinAngle; limits.max = limitMaxAngle; hj.limits = limits; } // If the horizontal position of the start point is bigger than the one of the end point if (startPoint.x > endPoint.x) { // Instantiate in the Flippers List a right Flipper object at the click position, with the angle of the vector flippersList.Add((GameObject)Instantiate(rightFlipper, new Vector3(hit.point.x + 2 * middle.x, hit.point.y + middle.y, channel.transform.position.z), Quaternion.Euler(0, 0, angle))); amountFlippers++; } // Put the new instantiation as the selected flipper index indexSelected = amountFlippers; // Reset the active flipper ResetActive(indexSelected); // Ignore collision with the postsynaptic neuron Physics.IgnoreCollision(postSynaptic.GetComponent <Collider>(), flippersList[amountFlippers].GetComponent <Collider>()); //Put back the firstClick to false firstClick = false; return; } }
protected override bool DetectSetup() { // detect axis doorHinge = GetDoor().GetComponent <HingeJoint>(); if (doorHinge && !doorHingeCreated) { direction = Direction.autodetect; } finalDirection = (direction == Direction.autodetect) ? DetectDirection() : direction; if (finalDirection == Direction.autodetect) { return(false); } if (doorHinge && !doorHingeCreated) { // if there is a hinge joint already it overrides axis selection direction = finalDirection; } // detect opening direction Bounds doorBounds = VRTK_SharedMethods.GetBounds(GetDoor().transform, transform); if (doorHinge == null || doorHingeCreated) { if (handles) { // determin sub-direction depending on handle location Bounds handleBounds = VRTK_SharedMethods.GetBounds(handles.transform, transform); switch (finalDirection) { case Direction.x: if ((handleBounds.center.z + handleBounds.extents.z) > (doorBounds.center.z + doorBounds.extents.z) || (handleBounds.center.z - handleBounds.extents.z) < (doorBounds.center.z - doorBounds.extents.z)) { subDirection = (handleBounds.center.y > doorBounds.center.y) ? -1 : 1; secondaryDirection = Vector3.up; } else { subDirection = (handleBounds.center.z > doorBounds.center.z) ? -1 : 1; secondaryDirection = Vector3.forward; } break; case Direction.y: if ((handleBounds.center.z + handleBounds.extents.z) > (doorBounds.center.z + doorBounds.extents.z) || (handleBounds.center.z - handleBounds.extents.z) < (doorBounds.center.z - doorBounds.extents.z)) { subDirection = (handleBounds.center.x > doorBounds.center.x) ? -1 : 1; secondaryDirection = Vector3.right; } else { subDirection = (handleBounds.center.z > doorBounds.center.z) ? -1 : 1; secondaryDirection = Vector3.forward; } break; case Direction.z: if ((handleBounds.center.x + handleBounds.extents.x) > (doorBounds.center.x + doorBounds.extents.x) || (handleBounds.center.x - handleBounds.extents.x) < (doorBounds.center.x - doorBounds.extents.x)) { subDirection = (handleBounds.center.y > doorBounds.center.y) ? -1 : 1; secondaryDirection = Vector3.up; } else { subDirection = (handleBounds.center.x > doorBounds.center.x) ? -1 : 1; secondaryDirection = Vector3.right; } break; } } else { switch (finalDirection) { case Direction.x: secondaryDirection = (doorBounds.extents.y > doorBounds.extents.z) ? Vector3.up : Vector3.forward; break; case Direction.y: secondaryDirection = (doorBounds.extents.x > doorBounds.extents.z) ? Vector3.right : Vector3.forward; break; case Direction.z: secondaryDirection = (doorBounds.extents.y > doorBounds.extents.x) ? Vector3.up : Vector3.right; break; } // TODO: derive how to detect -1 subDirection = 1; } } else { // calculate directions from existing anchor Vector3 existingAnchorDirection = doorBounds.center - doorHinge.connectedAnchor; if (existingAnchorDirection.x != 0) { secondaryDirection = Vector3.right; subDirection = existingAnchorDirection.x <= 0 ? 1 : -1; } else if (existingAnchorDirection.y != 0) { secondaryDirection = Vector3.up; subDirection = existingAnchorDirection.y <= 0 ? 1 : -1; } else if (existingAnchorDirection.z != 0) { secondaryDirection = Vector3.forward; subDirection = existingAnchorDirection.z <= 0 ? 1 : -1; } } if (doorHingeCreated) { float extents = 0; if (secondaryDirection == Vector3.right) { extents = doorBounds.extents.x / GetDoor().transform.lossyScale.x; } else if (secondaryDirection == Vector3.up) { extents = doorBounds.extents.y / GetDoor().transform.lossyScale.y; } else { extents = doorBounds.extents.z / GetDoor().transform.lossyScale.z; } doorHinge.anchor = secondaryDirection * subDirection * extents; doorHinge.axis = Direction2Axis(finalDirection); } if (doorHinge) { doorHinge.useLimits = true; doorHinge.enableCollision = true; JointLimits limits = doorHinge.limits; limits.min = openInward ? -maxAngle : 0; limits.max = openOutward ? maxAngle : 0; limits.bounciness = 0; doorHinge.limits = limits; } if (doorSnapForceCreated) { float forceToApply = (-5f * GetDirectionFromJoint()); doorSnapForce.relativeForce = GetThirdDirection(doorHinge.axis, secondaryDirection) * (subDirection * forceToApply); } return(true); }
// Use this for initialization void Start() { //first we need to define the Game object we're looking at Robot = GameObject.FindWithTag("Robot"); Debug.Log("found Robot "); //made mistake of not finding the Hips at all! Will do that and then overwrite itself. Torso = Robot.transform.Find("Torso").gameObject; Debug.Log("found Torso"); //Here we will set up the lowerAbs lowerAbs1 = Torso.transform.Find("lowerAbs1").gameObject; upperAbs1 = Torso.transform.Find("upperAbs1").gameObject; lowerAbs2 = Torso.transform.Find("lowerAbs2").gameObject; upperAbs2 = Torso.transform.Find("upperAbs2").gameObject; //now we make sure we have found that hip assembly if (lowerAbs1 != null && lowerAbs2 != null && upperAbs1 != null && upperAbs2 != null) { //Now we need to do our assignments which are the joint Hinges //==========LOWER ABS=============// LowerAbs1Joint = lowerAbs1.GetComponent <HingeJoint>(); LowerAbs1Motor = LowerAbs1Joint.motor; //Next we need to set up the Motor action setUpMotor(LowerAbs1Joint, LowerAbs1Motor); //Now we set up our joint limits LowerAbs1Limits = LowerAbs1Joint.limits; //Hinge2 lower LowerAbs2Joint = lowerAbs2.GetComponent <HingeJoint>(); LowerAbs2Motor = LowerAbs2Joint.motor; //Next we need to set up the Motor action setUpMotor(LowerAbs2Joint, LowerAbs2Motor); //Now we set up our joint limits LowerAbs2Limits = LowerAbs2Joint.limits; //==========UPPER ABS=============// UpperAbs1Joint = upperAbs1.GetComponent <HingeJoint>(); UpperAbs1Motor = UpperAbs1Joint.motor; //Next we need to set up the Motor action setUpMotor(UpperAbs1Joint, UpperAbs1Motor); //Now we set up our joint limits UpperAbs1Limits = UpperAbs1Joint.limits; //Hinge2 upper /*=================================NOT NEEDED UNTIL UPPER BODY IS ADDED==================== * UpperAbs2Joint = upperAbs2.GetComponent<HingeJoint>(); * UpperAbs2Motor = UpperAbs2Joint.motor; * //Next we need to set up the Motor action * setUpMotor(UpperAbs2Joint, UpperAbs2Motor); * * //Now we set up our joint limits * UpperAbs2Limits = UpperAbs2Joint.limits; * //Now we do our last little debug * * if (UpperAbs2Joint != null && UpperAbs1Joint != null && LowerAbs2Joint != null && LowerAbs1Joint != null) * { * Debug.Log("Abs fully assigned"); * } * else * { * Debug.Log("Ab Joints not found"); * }*/ } else { Debug.Log("Ab objects not found"); } }
private static JointLimits UpdateLimits(JointLimits jointLimits, float min, float max) { jointLimits.min = min; jointLimits.max = max; return(jointLimits); }
protected override bool DetectSetup() { finalDirection = (direction == Direction.autodetect) ? DetectDirection() : direction; if (finalDirection == Direction.autodetect) { return(false); } Bounds doorBounds = Utilities.GetBounds(getDoor().transform, transform); if (handles) { // determin sub-direction depending on handle location Bounds handleBounds = Utilities.GetBounds(handles.transform, transform); switch (finalDirection) { case Direction.x: if ((handleBounds.center.z + handleBounds.extents.z) > (doorBounds.center.z + doorBounds.extents.z) || (handleBounds.center.z - handleBounds.extents.z) < (doorBounds.center.z - doorBounds.extents.z)) { subDirection = (handleBounds.center.y > doorBounds.center.y) ? -1 : 1; secondaryDirection = Vector3.up; } else { subDirection = (handleBounds.center.z > doorBounds.center.z) ? -1 : 1; secondaryDirection = Vector3.forward; } break; case Direction.y: if ((handleBounds.center.z + handleBounds.extents.z) > (doorBounds.center.z + doorBounds.extents.z) || (handleBounds.center.z - handleBounds.extents.z) < (doorBounds.center.z - doorBounds.extents.z)) { subDirection = (handleBounds.center.x > doorBounds.center.x) ? -1 : 1; secondaryDirection = Vector3.right; } else { subDirection = (handleBounds.center.z > doorBounds.center.z) ? -1 : 1; secondaryDirection = Vector3.forward; } break; case Direction.z: if ((handleBounds.center.x + handleBounds.extents.x) > (doorBounds.center.x + doorBounds.extents.x) || (handleBounds.center.x - handleBounds.extents.x) < (doorBounds.center.x - doorBounds.extents.x)) { subDirection = (handleBounds.center.y > doorBounds.center.y) ? -1 : 1; secondaryDirection = Vector3.up; } else { subDirection = (handleBounds.center.x > doorBounds.center.x) ? -1 : 1; secondaryDirection = Vector3.right; } break; } } else { switch (finalDirection) { case Direction.x: secondaryDirection = (doorBounds.extents.y > doorBounds.extents.z) ? Vector3.up : Vector3.forward; break; case Direction.y: secondaryDirection = (doorBounds.extents.x > doorBounds.extents.z) ? Vector3.right : Vector3.forward; break; case Direction.z: secondaryDirection = (doorBounds.extents.y > doorBounds.extents.x) ? Vector3.up : Vector3.right; break; } subDirection = 1; } if (doorHjCreated) { doorHj.anchor = secondaryDirection * subDirection * 0.5f; switch (finalDirection) { case Direction.x: doorHj.axis = new Vector3(1, 0, 0); break; case Direction.y: doorHj.axis = new Vector3(0, 1, 0); break; case Direction.z: doorHj.axis = new Vector3(0, 0, 1); break; } } if (doorHj) { doorHj.useLimits = true; doorHj.enableCollision = true; JointLimits limits = doorHj.limits; limits.min = openInward ? -maxAngle : 0; limits.max = openOutward ? maxAngle : 0; limits.bounciness = 0; doorHj.limits = limits; } if (doorCfCreated) { doorCf.force = getThirdDirection(doorHj.axis, secondaryDirection) * subDirection * -50f; } return(true); }
private void FixedUpdate() { if (joint == null) { return; } float jointAngle = GetJointAngle(); bool flag = GrabManager.IsGrabbedAny(joint.gameObject); if (!grabbed && flag) { grabbedInGear = gear; } grabbed = flag; if (grabbed) { if (jointAngle <= (reverseAngle + neutralAngle) / 2f) { gear = -1; } else if (jointAngle <= (neutralAngle + firstAngle) / 2f) { gear = 0; } else if (jointAngle <= (firstAngle + secondAngle) / 2f) { gear = 1; } else { gear = 2; } JointLimits limits = joint.limits; limits.min = reverseAngle; if (grabbedInGear < 1) { if (gear == 2) { gear = 1; } limits.max = firstAngle; } else { limits.max = secondAngle; } joint.SetLimits(limits); if (steeringWheel != null) { JointSpring spring = steeringWheel.spring; spring.spring = ((gear != 2) ? centeringSpring1st : centeringSpring2st); steeringWheel.spring = spring; } } float value = 0f; JointSpring spring2 = joint.spring; switch (gear) { case -1: spring2.targetPosition = reverseAngle; value = reverseValue; break; case 0: spring2.targetPosition = neutralAngle; value = 0f; break; case 1: spring2.targetPosition = firstAngle; value = firstValue; break; case 2: spring2.targetPosition = secondAngle; value = secondValue; break; } joint.SetSpring(spring2); output.SetValue(value); }
public static JointValues RandomJointValues(JointLimits limits, Random rng = null) { return(JointValues.Random(limits, rng ?? ThreadSafeRandom.Generator)); }
void InitializeFingerJoints() { hinges = new HingeJoint[3]; for (int i = 1; i < bones.Length - 1; ++i) { if (bones[i] != null) { if (i == 1) { rootJoint = Palm.gameObject.AddComponent <ConfigurableJoint>(); rootJoint.configuredInWorldSpace = false; rootJoint.connectedBody = bones[i].GetComponent <Rigidbody>(); origJointRotation = new Quaternion(bones[i].rotation.x, bones[i].rotation.y, bones[i].rotation.z, bones[i].rotation.w); origPalmRotation = new Quaternion(Palm.rotation.x, Palm.rotation.y, Palm.rotation.z, Palm.rotation.w); origPalmToJointRotation = Quaternion.Inverse(origPalmRotation) * origJointRotation; rootJoint.rotationDriveMode = RotationDriveMode.Slerp; rootJoint.enablePreprocessing = true; rootJoint.autoConfigureConnectedAnchor = false; rootJoint.anchor = Palm.transform.InverseTransformPoint(bones[i].TransformPoint(new Vector3(0f, 0f, (bones[i].GetComponent <CapsuleCollider>().radius) - (bones[i].GetComponent <CapsuleCollider>().height / 2f)))); rootJoint.connectedAnchor = new Vector3(0f, 0f, (bones[i].GetComponent <CapsuleCollider>().radius) - (bones[i].GetComponent <CapsuleCollider>().height / 2f)); //rootJoint.axis = Palm.transform.InverseTransformDirection(bones[i].transform.right); //rootJoint.secondaryAxis = Palm.transform.InverseTransformDirection(bones[i].transform.forward); rootJoint.enableCollision = false; rootJoint.hideFlags = HideFlags.DontSave | HideFlags.DontSaveInEditor; rootJoint.xMotion = ConfigurableJointMotion.Locked; rootJoint.yMotion = ConfigurableJointMotion.Locked; rootJoint.zMotion = ConfigurableJointMotion.Locked; //rootJoint.angularYMotion = ConfigurableJointMotion.Locked; //rootJoint.angularZMotion = ConfigurableJointMotion.Locked; JointDrive motorMovement = new JointDrive(); motorMovement.maximumForce = 5000000f; motorMovement.positionSpring = 5000000f; rootJoint.slerpDrive = motorMovement; } if (i + 1 < bones.Length) { HingeJoint Hinge = bones[i].gameObject.AddComponent <HingeJoint>(); Hinge.enablePreprocessing = true; Hinge.autoConfigureConnectedAnchor = false; Hinge.connectedBody = bones[i + 1].gameObject.GetComponent <Rigidbody>(); Hinge.anchor = bones[i].InverseTransformPoint(bones[i + 1].TransformPoint(new Vector3(0f, 0f, (bones[i + 1].GetComponent <CapsuleCollider>().radius) - (bones[i + 1].GetComponent <CapsuleCollider>().height / 2f)))); Hinge.connectedAnchor = new Vector3(0f, 0f, (bones[i + 1].GetComponent <CapsuleCollider>().radius) - (bones[i + 1].GetComponent <CapsuleCollider>().height / 2f)); Hinge.axis = bones[i].InverseTransformDirection(bones[i + 1].transform.right); Hinge.enableCollision = false; Hinge.hideFlags = HideFlags.DontSave | HideFlags.DontSaveInEditor; Hinge.useMotor = true; Hinge.useLimits = true; JointLimits limit = new JointLimits(); limit.min = -70f; limit.max = 15f; Hinge.limits = limit; hinges[i] = Hinge; } } } }
public void Apply() { isActive = true; skeleton = skeletonAnim.Skeleton; mix = 1; var ragdollRootBone = skeleton.FindBone(startingBoneName); startingBone = ragdollRootBone; RecursivelyCreateBoneProxies(ragdollRootBone); rootRigidbody = boneTable[ragdollRootBone].GetComponent <Rigidbody>(); rootRigidbody.isKinematic = pinStartBone; rootRigidbody.mass = rootMass; List <Collider> boneColliders = new List <Collider>(); foreach (var pair in boneTable) { var b = pair.Key; var t = pair.Value; Bone parentBone = null; Transform parentTransform = transform; boneColliders.Add(t.GetComponent <Collider>()); if (b != startingBone) { parentBone = b.Parent; parentTransform = boneTable[parentBone]; } else { ragdollRoot = new GameObject("RagdollRoot").transform; ragdollRoot.parent = transform; if (b == skeleton.RootBone) { ragdollRoot.localPosition = new Vector3(b.WorldX, b.WorldY, 0); ragdollRoot.localRotation = Quaternion.Euler(0, 0, GetCompensatedRotationIK(b)); parentTransform = ragdollRoot; } else { ragdollRoot.localPosition = new Vector3(b.Parent.WorldX, b.Parent.WorldY, 0); ragdollRoot.localRotation = Quaternion.Euler(0, 0, GetCompensatedRotationIK(b.Parent)); parentTransform = ragdollRoot; } rootOffset = t.position - transform.position; } var rbParent = parentTransform.GetComponent <Rigidbody>(); if (rbParent != null) { var joint = t.gameObject.AddComponent <HingeJoint>(); joint.connectedBody = rbParent; Vector3 localPos = parentTransform.InverseTransformPoint(t.position); localPos.x *= 1; joint.connectedAnchor = localPos; joint.axis = Vector3.up; joint.GetComponent <Rigidbody>().mass = joint.connectedBody.mass * massFalloffFactor; JointLimits limits = new JointLimits(); limits.min = -rotationLimit; limits.max = rotationLimit; joint.limits = limits; joint.useLimits = true; joint.enableCollision = enableJointCollision; } } 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]); } } var utilityBones = GetComponentsInChildren <SkeletonUtilityBone>(); if (utilityBones.Length > 0) { List <string> destroyedUtilityBoneNames = new List <string>(); foreach (var ub in utilityBones) { if (ub.mode == SkeletonUtilityBone.Mode.Override) { destroyedUtilityBoneNames.Add(ub.gameObject.name); Destroy(ub.gameObject); } } if (destroyedUtilityBoneNames.Count > 0) { string msg = "Destroyed Utility Bones: "; for (int i = 0; i < destroyedUtilityBoneNames.Count; i++) { msg += destroyedUtilityBoneNames[i]; if (i != destroyedUtilityBoneNames.Count - 1) { msg += ","; } } Debug.LogWarning(msg); } } if (disableIK) { foreach (IkConstraint ik in skeleton.IkConstraints) { ik.Mix = 0; } } skeletonAnim.UpdateWorld += UpdateWorld; }
protected override void OnSimulateStart() { //BrakeKey = GetKey(Brake); HJ = GetComponent <HingeJoint>(); Colliders = GetComponentsInChildren <Collider>(); MyId = GetComponent <BlockVisualController>().ID; angleDrag = GetComponent <Rigidbody>().angularDrag; JointLimits jl = HJ.limits; jl.min = jl.max = jl.bounciness = jl.bounceMinVelocity = 0; HJ.limits = jl; HJ.spring = new JointSpring() { damper = 10000, spring = 10000, targetPosition = 0 }; if (Collider) { //禁用原有碰撞 foreach (Collider c in Colliders) { if (c.name == "CubeColliders") { c.enabled = false; } } WheelCollider = new GameObject("Wheel Collider"); mFilter = WheelCollider.AddComponent <MeshFilter>(); mFilter.mesh = WheelMesh = SimpleMesh.MeshFromObj(Application.dataPath + "/Mods/Resources/BlockEnhancement/Wheel.obj"); mCollider = WheelCollider.AddComponent <MeshCollider>(); mCollider.convex = true; PM = mCollider.material; //静摩擦力 PM.staticFriction = Friction; //动摩擦力 PM.dynamicFriction = Friction; //摩擦力组合 PM.frictionCombine = PhysicMaterialCombine.Multiply; //弹力 PM.bounciness = 0; //弹力组合 PM.bounceCombine = PhysicMaterialCombine.Minimum; #if DEBUG mRenderer = WheelCollider.AddComponent <MeshRenderer>(); mRenderer.material.color = Color.red; #endif PaS pas = GetPositionAndScale(MyId); WheelCollider.transform.parent = mCollider.transform.parent = transform; WheelCollider.transform.rotation = mCollider.transform.rotation = transform.rotation; WheelCollider.transform.position = mCollider.transform.position = transform.TransformPoint(transform.InverseTransformPoint(transform.position) + pas.Position); WheelCollider.transform.localScale = mCollider.transform.localScale = pas.Scale; WheelCollider.AddComponent <DestroyIfEditMode>(); } else if (FrictionT) { //设置原有碰撞的参数 foreach (Collider c in Colliders) { if (c.name == "CubeColliders") { PhysicMaterial PM = c.GetComponent <BoxCollider>().material; //静摩擦力 PM.staticFriction = Friction; //动摩擦力 PM.dynamicFriction = Friction; Debug.Log(PM.bounciness); //摩擦力组合 PM.frictionCombine = PhysicMaterialCombine.Multiply; //弹力 PM.bounciness = 0; //弹力组合 PM.bounceCombine = PhysicMaterialCombine.Minimum; } } } if (MyId == (int)BlockType.Wheel || MyId == (int)BlockType.LargeWheel) { CMCH = GetComponent <CogMotorControllerHinge>(); CMCH.speedLerpSmooth = Lerp; } }
protected virtual void Start() { car = FindObjectOfType <CarMovementControl>().gameObject; joint = GetComponent <HingeJoint>(); limit = joint.limits; }
private void INTERNAL_get_limits(out JointLimits value){}
void DoSetProperties() { JointSpring _springJoint = _joint.spring; JointMotor _jointMotor = _joint.motor; JointLimits _jointLimits = _joint.limits; if (!connectedBody.IsNone) { _joint.connectedBody = connectedBody.Value.rigidbody; } if (!anchor.IsNone) { _joint.anchor = anchor.Value; } if (!axis.IsNone) { _joint.axis = axis.Value; } if (!useSpring.IsNone) { _joint.useSpring = useSpring.Value; } if (!spring.IsNone) { _springJoint.spring = spring.Value; _joint.spring = _springJoint; } if (!damper.IsNone) { _springJoint.damper = damper.Value; _joint.spring = _springJoint; } if (!targetPosition.IsNone) { _springJoint.targetPosition = targetPosition.Value; _joint.spring = _springJoint; } if (!useMotor.IsNone) { _joint.useMotor = useMotor.Value; } if (!targetVelocity.IsNone) { _jointMotor.targetVelocity = targetVelocity.Value; _joint.motor = _jointMotor; } if (!force.IsNone) { _jointMotor.force = force.Value; _joint.motor = _jointMotor; } if (!freeSpin.IsNone) { _jointMotor.freeSpin = freeSpin.Value; _joint.motor = _jointMotor; } if (!useLimits.IsNone) { _joint.useLimits = useLimits.Value; } if (!min.IsNone) { _jointLimits.min = min.Value; _joint.limits = _jointLimits; } if (!max.IsNone) { _jointLimits.max = max.Value; _joint.limits = _jointLimits; } if (!minBounce.IsNone) { _jointLimits.minBounce = minBounce.Value; _joint.limits = _jointLimits; } if (!maxBounce.IsNone) { _jointLimits.maxBounce = maxBounce.Value; _joint.limits = _jointLimits; } }
private void INTERNAL_set_limits(ref JointLimits value){}
public void writeKeyVal(string key, JointLimits val) { writeKey(key); writeRawValue(val); }