public void ForceDetach() { for (int i = 0; i < bonesCount; i++) { RagdollPhysics.DetachRigidbody(allElements[i].rigidbody, null, true); } }
public static void ReleaseGrabPoint(GrabPoint grabPoint) { if (grabPoint != null) { RagdollPhysics.DetachRigidbody(grabPoint.baseRigidbody, null, true); ReesetGrabPoint(grabPoint); grabPoint.gameObject.SetActive(false); } }
void UpdatePhysicsFly() { // keep our forward facing our velocity, to simulate an arc // if we're not already collided, and using physics if (!collidedDuringPhysicsFly && !rb.isKinematic) { RagdollPhysics.SimulateArc(rb); } }
public void Detach() { grabPoint.Detach(); for (int x = 0; x < physicsHit.hitElements.Count; x++) { RagdollPhysics.DetachRigidbody(physicsHit.hitElements[x].rigidbody, connectedJoints[x], false); } connectedJoints.Clear(); }
void UpdateArcSimulation() { // keep our forward facing our velocity, to simulate an arc // if we're not already collided, using physics, and not skewering if (!collidedDuringPhysicsFly) { if (!rb.isKinematic && skeweredCount == 0) { RagdollPhysics.SimulateArc(rb); } } }
public GrabbedBody(PhysicsHit physicsHit, Quaternion rotation) { this.physicsHit = physicsHit; grabPoint = GrabPoint.GetGrabPoint(); grabPoint.transform.position = physicsHit.averagePosition; grabPoint.transform.rotation = rotation; for (int x = 0; x < physicsHit.hitElements.Count; x++) { connectedJoints.Add(RagdollPhysics.GrabRigidbody(physicsHit.hitElements[x].rigidbody, grabPoint.childRigidbody, false)); } }
void Awake() { if (rigidbodyToHang) { if (calculateOffset) { RagdollPhysics.HangRigidbody(rigidbodyToHang, GetComponent <Rigidbody>()); } else { RagdollPhysics.HangRigidbody(rigidbodyToHang, GetComponent <Rigidbody>(), connectedAnchorOffset); } } }
void Start() { if (rigidbodyToHang) { if (calculateOffset) { RagdollPhysics.GrabRigidbody(rigidbodyToHang, GetComponent <Rigidbody>(), freeRotation); } else { RagdollPhysics.GrabRigidbody(rigidbodyToHang, GetComponent <Rigidbody>(), anchorOffset, freeRotation); } } }
static void ReesetGrabPoint(GrabPoint p) { // detach our grab point, if it was attached at all RagdollPhysics.DetachRigidbody(p.baseRigidbody, null, true); p.baseRigidbody.isKinematic = true; p.baseRigidbody.useGravity = false; p.childRigidbody.transform.SetParent(p.baseRigidbody.transform); p.childRigidbody.transform.localPosition = Vector3.zero; p.childRigidbody.transform.localRotation = Quaternion.identity; RagdollPhysics.MakeJointDefault(p.baseJoint, freeRotation: false, Vector3.zero, Vector3.zero, p.baseRigidbody); }
void ReachDestination(float velocityMultiplier) { reachedDestination = true; EnableCollider(true); // if we're not sticking into a wall if (!stickToEnd) { // turn on the rigidbody rb.isKinematic = false; //for each grabbed rigidbody we've impaled, for (int i = startIndexForSkewered; i < grabbedBodies.Count; i++) { Rigidbody grabPointRB = grabbedBodies[i].grabPoint.baseRigidbody; // need to disable kinematic here to avoid jittery physics grabPointRB.isKinematic = false; // set all associated rigidbody velocities to zero, or else the leftover momentum // builds up and keeps us shooting forward beyond our control... grabPointRB.velocity = Vector3.zero; grabbedBodies[i].grabPoint.childRigidbody.velocity = Vector3.zero; if (physicsHits[i].isRagdoll) { physicsHits[i].ragdoll.SetVelocity(Vector3.zero); } else { physicsHits[i].mainRigidbody.velocity = Vector3.zero; } // attach it to our spear rigidbody via a joint RagdollPhysics.GrabRigidbody(grabPointRB, rb, false); } // set our velocity to the spear speed rb.velocity = launchRay.direction * velocity * velocityMultiplier; } }
public List <PhysicsHit> ShootImpaler(float velocity, float hitObjectVelocityMultiplier, float zMovementLimit, Ray ray, float maxDistance, LayerMask mask, float impalerRadius, bool kinematicOnReach, bool useColliderOnReach, float lifeTime, System.Action <PhysicsHit> onReachHitObject) { this.onReachHitObject = onReachHitObject; this.kinematicOnReach = kinematicOnReach; this.useColliderOnReach = useColliderOnReach; this.impalerRadius = impalerRadius; InitializeLaunch(ray, velocity, lifeTime, hitObjectVelocityMultiplier); reachedIndicies.Clear(); //grab any rigidbodies along a ray, until a static collider bool hitStatic; RagdollPhysics.ShootMultiGrabRay(ray, impalerRadius, mask, maxDistance, grabbedBodies, physicsHits, out endPointDistance, out hitStatic); //for each grabbed rigidbody we've impaled, // attach it to our impaler rigidbody via a joint for (int i = 0; i < grabbedBodies.Count; i++) { // need to disable kinematic here to avoid jittery physics // grabbedGroups[i].grabPoint.baseRigidbody.isKinematic = false; RagdollPhysics.GrabRigidbody(grabbedBodies[i].grabPoint.baseRigidbody, rb, false); // allow joint movement along teh z axis, // so rigidbodies can slide along the impaler (helps stability) ConfigurableJoint joint = grabbedBodies[i].grabPoint.baseJoint; joint.zMotion = ConfigurableJointMotion.Limited; var l = joint.linearLimit; l.limit = zMovementLimit; joint.linearLimit = l; } StartCollisionIgnoreWithMyCollider(physicsHits); AdjustCapsulCollider(endPointDistance, impalerRadius); return(physicsHits); }
public void DismemberBone(string reason, Ragdoll ragdoll, RagdollTransform bone) { InitializeDismemberedBones(); if (!dismembermentAvailable) { return; } if (!BoneDismemberable(bone.bone.bone)) { return; } if (RagdollPhysics.RigidbodyGrabbed(bone.rigidbody)) { return; } // Debug.LogError("Dismembered " + reason); dismemberedBones[bone.bone.bone] = bone; // dismember the follow target, so it reflects our dismemberment // (dismembers the animated model...) if (bone.followTarget != null) { DismemberBone(ragdoll, bone.followTarget, true); } // dismember and disable any child bones (helps physics from getting all jittery) HumanBodyBones childBone = Ragdoll.GetChildBone(bone.bone.bone); RagdollTransform childBoneTransform = ragdoll.GetBone(childBone); if (!BoneDismembered(childBoneTransform)) { DismemberBone(reason, ragdoll, childBoneTransform); } ragdoll.StartCoroutine(DismemberBoneDelayed(ragdoll, bone)); }
public PhysicsHit Launch(float velocity, Ray ray, float maxDistance, float radiusCheck, LayerMask layerMask, float lifeTime, float hitObjectVelocityMultiplier, bool simulateArc, System.Action <PhysicsHit> onReachHitObject) { this.simulateArc = simulateArc; this.onReachHitObject = onReachHitObject; InitializeLaunch(ray, velocity, lifeTime, hitObjectVelocityMultiplier); if (!simulateArc) { transform.rotation = Quaternion.Euler(Random.Range(0, 360), Random.Range(0, 360), Random.Range(0, 360)); } physicsHit = RagdollPhysics.SphereCast(ray, radiusCheck, layerMask, maxDistance); if (physicsHit != null) { Collider hitCollider = physicsHit.hitElements[0].collider; transform.SetParent(hitCollider.transform); localHitPoint = hitCollider.transform.InverseTransformPoint(physicsHit.averagePosition); startLocalPosition = transform.localPosition; endPointDistance = physicsHit.hitDistance; StartCollisionIgnoreWithMyCollider(new List <PhysicsHit>() { physicsHit }); DynamicRagdoll.Demo.GameTime.SetTimeDilation(.5f, .1f, 10, .1f); } else { EnablePhysics(true); rb.velocity = ray.direction * velocity; collidedDuringPhysicsFly = false; reachedDestination = true; } return(physicsHit); }
/* * make our collider ignore collisions with the supplied colliders in the physics hit list */ protected void StartCollisionIgnoreWithMyCollider(List <PhysicsHit> physicsHits) { RagdollPhysics.MakePhysicsHitsIgnoreCollider(physicsHits, myCollider, myColliderIgnorePairs); }
public void Detach() { RagdollPhysics.DetachRigidbody(baseRigidbody, null, true); ReesetGrabPoint(this); gameObject.SetActive(false); }
public List <PhysicsHit> ShootSpear(float velocity, Ray ray, float maxDistance, LayerMask skewerMask, float lifeTime, float skewerSeperation, float minSpaceFromWall, float hitObjectVelocityMultiplier, System.Action <PhysicsHit, bool> onReachHitObject) { this.onReachHitObject = onReachHitObject; collidedDuringPhysicsFly = false; InitializeLaunch(ray, velocity, lifeTime, hitObjectVelocityMultiplier); reachedIndicies.Clear(); //grab any rigidbodies along a ray, until a static collider Vector3 endPoint = RagdollPhysics.ShootMultiGrabRay(ray, spearRadius, skewerMask, maxDistance, grabbedBodies, physicsHits, out endPointDistance, out stickToEnd); int hitCount = grabbedBodies.Count; // if we have no wall to stick to if (!stickToEnd) { //if we have some rigidbodies to impale, recalculate an end point after the last one if (hitCount > 0) { PhysicsHit furthestHit = physicsHits[hitCount - 1]; endPoint = furthestHit.hitElements[furthestHit.hitElements.Count - 1].hitPoint + ray.direction * spearLength; endPointDistance = Vector3.Distance(ray.origin, endPoint); } else { // turn on physics and just use our velocity to "fly" ReachDestination(1); } } // this is true already if we didnt hit anything if (!reachedDestination) { // if we have any impaled rigidbodies if (hitCount > 0) { // where each grabbed rigidbody will end up skewerTargets = new Vector3[hitCount]; skewerOffsets = new float[hitCount]; // the first index that is being skewered startIndexForSkewered = hitCount; // calculate where each grabbed rigidbody will end up: float lastEndPoint = minSpaceFromWall; for (int i = hitCount - 1; i >= 0; i--) { float skewerOffset; skewerTargets[i] = CalculateSkewerTargetPosition(endPoint, ray.direction, skewerSeperation, DetermineHitPointsSize(physicsHits[i], ray.direction, skewerMask), ref lastEndPoint, out skewerOffset); skewerOffsets[i] = skewerOffset; // if we have enough space on teh spear, skewer this index if (skewerOffset < spearLength) { startIndexForSkewered = i; } // if not we'll just add force to it (or dismember it) when the spear reaches it } StartCollisionIgnoreWithMyCollider(physicsHits); DynamicRagdoll.Demo.GameTime.SetTimeDilation(.5f, .1f, 10, .1f); } // randomly offset the amount the spear model sticks out of the end point randomOffset = Random.Range(-tipLength * .5f, 0); modelEndTarget = endPoint + ray.direction * randomOffset; } return(physicsHits); }
/* * make our collider stop ignoring collisions */ void EndColliderIgnore() { RagdollPhysics.EndPhysicsHitsIgnoreCollider(myColliderIgnorePairs); }
protected override void DisableProjectile() { // clear all physics joints we used for impalement RagdollPhysics.DetachGrabbedBodies(grabbedBodies); }
public bool RigidbodyGrabbed() { return(RagdollPhysics.RigidbodyGrabbed(rigidbody)); }